Essentially I am trying to create a function, r_sum(n), that will return the sum of the first "n" reciprocals: e.g. sum(5) = 1 + 1/2 + 1/3 + 1/4 + 1/5 .I am new to recursion and am having trouble with the implementation. Here is the code I have so far:
def r_sum(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return 1/n
I think I have created the base of the function, but I'm not sure where I would have the function call itself. As of now, I realize the function will only return the value of 1/n. How can I add to this so that I have the function call itself to calculate this sum?