CBSE Class 11 Computer Science
Question 145 of 161
Flow of Control — Question 22
Back to all questions 22
Question Question 21
Write a Python program to sum the sequence:
1 + 1/1! + 1/2! + 1/3! + ..... + 1/n! (Input n)
Solution
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