Python Program for Program 求一个Series 1/1的总和! + 2/2! + 3/3! + 4/4! +…….+ n/n!
您已获得系列 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!,找出系列的总和,直到第 n 项。
例子:
Input :n = 5
Output : 2.70833
Input :n = 7
Output : 2.71806
# Python code to find smallest K-digit
# number divisible by X
def sumOfSeries(num):
# Computing MAX
res = 0
fact = 1
for i in range(1, num+1):
fact *= i
res = res + (i/ fact)
return res
n = 5
print("Sum: ", sumOfSeries(n))
# Code contributed by Mohit Gupta_OMG <(0_o)>
输出:
Sum: 2.70833
请参阅有关程序的完整文章以查找系列 1/1 的总和! + 2/2! + 3/3! + 4/4! +…….+ n/n!更多细节!