129. Python Program to Compute the Given Series 1 - x^2/(2^2*1!) + x^4/(2^4*2!) – x^6/(2^6*3!)
How does this program work?
- This program is used to find the Sum of the given series 1 - x^2/(2^2*1!) + x^4/(2^4*2!) – x^6/(2^6*3!) using Python.
- The integer entered by the user is stored in variable x and n .
- By using the for loop condition we can easily calculate the sum of given series.
Here is the code
import math
x = int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
s = 1
term = 1
y = 2
for i in range(1,n):
fact = 1
for j in range(1,y+1):
fact = fact * j
term = term * (-1)
m = term * math.pow(x, y) / fact
s = s + m
y += 2
print("Sum of series: ",s)