I need to get the approximation of sin(x) using Taylor expansion:
Here is the Code:
def factorial(number): # Factorial Function s = 1 for k in range(1, number): s *= k return sceta = eval(input("Enter angle of sin: "))x = (ceta * 3.14) / 360 # Change from degree to radiann = 15sin = xmult = -1for i in range(3, n+1, 2): # The 2 step will skip from 3 to 5 to 7 and so on until 15. sin += (x ** i) / factorial(i) * mult mult = mult * -1print("sin of", ceta, "is", sin)
The factorial function works fine, the problem is in the for loop, but I cannot find it.
I entered sin( 30 ) in the RUN, but it gives me 0.258 instead of 0.5