Q. Write a recursive function to add the first 'n' terms of the series:

1+1/2-1/3+1/4-1/5……


Answer =


def add(n):
    if n==term+1:
        return 0
    elif n%2 == 0 :
        return add(n+1) + 1/n
    elif n%2 != 0 :
        return add(n+1) - 1/n
    
term = int(input("Enter the terms :- "))
print(add(2)+1)

Output :-

Enter the terms :- 6
1.3833333333333333

>>>

Enter the terms :- 19
1.281228596824572
>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post