Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Problem :

Given an integer, calculate and print the value of the following series:
𝟏 𝟏 𝟏
𝟏 + 𝟐! + 𝟑! + ⋯ + 𝒏!

Input Format
A single line containing a positive integer n.

Constraint
0 ≤ 𝑛 ≤ 100

Output Format
Print the calculated value of the series as a float

Sample Input 0

Sample Output 0

1.7166666666666668

Solution:
def factorial(n):
fact=1
if(n==0):
fact=1
else:
for i in range(1,n+1):
fact=fact*i
return fact
sum=0
n=int(input())
for j in range(1,n+1):
f=factorial(j)
sum=sum+(1.0/f)

print(sum)

You might also like