KnowledgeBoat Logo

Computer Science

Write a Python program to sum the sequence:

1 + 1/1! + 1/2! + 1/3! + ….. + 1/n! (Input n)

Python

Python Control Flow

55 Likes

Answer

n = int(input("Enter the value of n: "))
sum = 0

for i in range(n + 1) :
    fact = 1
    for j in range(1, i) :
        fact *= j
    term = 1 / fact
    sum += term

print("Sum =", sum)

Output

Sum = 3.708333333333333

Answered By

30 Likes


Related Questions