I have this code:
n = int(input("Enter a positive integer n:\n"))
x = float(input("Enter a positive real number x :\n"))
def f(term_, i):
return term_*x/(i-1)
sum = 1
for i in range(1, n+1):
term = 1
for k in range(2*i, 0, -1):
term = f(term, k+1)
sum = sum + term * (-1) **i
print("w =",sum)
and I have a test case:
n = 5
x = 3.14
w = -1.0018168365436917
the code is supposed to return -1.0018168365436917
, but it is currently returning -1.0018168365436928
No importing of libraries to round off is permitted to do this task. Can anyone offer some advice