
import math
s={}
for step in range(1,100):
a = 1.15
x = 1
for i in range(1,step,1):
x+=a**i*1/math.factorial(i)
print(x)
error=abs(x-math.e**a)
s[step]=error
print(s)
st = sorted(s.items(), key=lambda x: x[1])
print(f'从1开始,循环到{st[0][0]},即可达最优值')
循环到第19步时就与math.e计算结果相同