```python
PTA Python-第四章13
前面的是求e的函数,因为我直接返回了值sum,所以后面只需要定义一个i,做一个while循环就可以了
def e(n):
a = 1
sum = 1
for i in range(1,n+1):
a*=i
sum+=1/a
return sum
m = float(input())
i = 1
while True:
e1 = e(i)
i+=1
e2 = e(i)
if e2-e1<m:
print("%.6f"%(e2))
break
2020-08-18
最新推荐文章于 2025-06-04 16:07:42 发布