KnowledgeBoat Logo

Computer Science

Write programs to find the sum of the following series:

x - x2/2! + x3/3! - x4/4! + x5/5! - x6/6! (Input x)

Python

Python Control Flow

84 Likes

Answer

x = int(input("Enter the value of x: "))

sum = 0
m = 1

for i in range(1, 7) :
    fact = 1
    for j in range(1, i+1) :
        fact *= j
    term = x ** i / fact
    sum += term * m
    m = m * -1

print("Sum =", sum)

Output

Enter the value of x: 2
Sum = 0.8444444444444444

Answered By

30 Likes


Related Questions