# Sine series
import math
def fn_x(x, term):
return (math.pow(x,term))
def fn_fact(term):
if(term==0):
return 1
else:
return term*fn_fact(term-1)
x = int(input("Enter value of x : "))
n = int(input("Enter number of terms : "))
Sine_series = 0
i = 1
p = 1
for count in range(0,n+1):
Sine_series = Sine_series+(i * (fn_x(x,p) / fn_fact(p)))
p = p+2
i = i*(-1)
print("Sine series = ", round(Sine_series,4))
"""
Sample output
>python sine_series.py
Enter value of x : 2
Enter number of terms : 5
Sine series = 0.9093
"""
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu