1
I’m having trouble organizing a recursive summation formula in Python. I need to calculate:
My code:
def seq1(n):
if n == 1:
return n
return seq1(n-1)+(-1**(n+1)/n)
I keep getting the same error for almost every change:
RecursionError: maximum recursion depth exceeded in comparison
I would like to know how to do the calculation, thanks in advance!
For any
0 < n < 997
its function seems to work (I did not check the results). If you need to calculate for values outside this range, recursiveness is not the solution, but for didactic purposes, read onsys.setrecursionlimit
– Woss
Thank you Anderson!
– Breno Nahuz