I need to write a function that is the recursive version of summing up numbers 1 through n. It needs to be recursive, which I have no idea how to do, although I did the iterative version quite easily.
All I know about recursion is that you call the function in the function. Any help on where to get started is greatly appreciated.
Here is the iterative version I did.
def summ(n):
result = 0
for i in range(1,n+1,1):
result = result + i
return result
sumfrom1toncan be described as:nplus thesumof1ton-1." While you still have to define base cases and such, I've always found a good sentence helps me visualize the execution.