Q:

sum of squares recursion

I have to write a recursive function sumSquares() that takes a non-negative (>= 0) integer n as a parameter and returns the sum of the squares of the numbers between 1 and n. Example:
>>>sumSquares(2)
5
>>>sumSquares(3)
14

This is what I have so far:
def sumSquares(n):
    if n==0:
        return 0
    else:
        return sumSquares(n-1)+sumSquares(n-1)

Can I also have an  explanation of what you did, I'm still in the process of learning recursion, and it would help a lot. Thanks.

A:

Shouldn't that be
return n * n + sumSquares(n - 1)

A:

Say you represent your function by S(x), x>0
S(x) = 1^2 + 2^2 + ... x^2

this can be written as 
S(x) = (1^2 + 2^2 + ...(x-1)^2 )+ x^2

S(x) = S(x-1) + x^2. 

Now for the program. 
def sumSquares(n):
        return sumSquares(n-1)+ n*n

But the problem is this doesn't know when to stop. We have to give a base case that tells it when to stop. 
You know that S(0) = 0 or S(1) = 1.
therefore
def sumSquares(n):
    assert n >= 0
    if (n == 0):
        return 0
    else:
        return sumSquares(n-1)+ n*n

