125. Python Program to Compute the Sine Series 1 - x^3/3! + x^5/5! – x^7/7! + …… x^n/n!
How does this program work?
- This program is used to find the Sum of the given Sine series 1 - x^3/3! + x^5/5! – x^7/7! + …… x^n/n! using Python.
- The integer entered by the user is stored in variable x and n but x value in degrees.
- By using the for loop condition we can easily calculate the sum of sine series.
Here is the code
x = int(input( "Enter the value of x: "))
n = int(input( "Enter the value of n: "))
i = 1
sum = 0
while i <= n:
fact = 1
j = 1
while j <= 2 * i - 1:
fact *= j
j += 1
sum += pow(-1, i+1) * pow(x, 2 * i - 1) / fact
i += 1
print('The sum of the series is', sum)