+ 1

Can anyone show why the given code to calculate the value of sin(x) using Taylor series expansion not working properly?

import math as m def sinse(x,n): sume=0 for i in range(n+1): sume+=(m.pow(-1,i)*m.pow(x,2*i+1)/m.factorial(2*i+1)) return sume n=int(input('Enter the value of n:')) x=int(input('enter the value of X:')) print(sinse(x,n))

20th Nov 2019, 8:54 AM
Rayyan
Rayyan - avatar
1 Antwort
0
Your line... return sume ...needs to be de-indented to line up with the for loop. It is currently terminating on the first iteration of the loop (when i is 0).
23rd Nov 2019, 11:44 AM
Russ
Russ - avatar