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计算结果相同
def fun(x):
import math
a, b, c, n = 1, 1, 1, 1
while n <= 100:
a = a * x / n
b = b + a
n += 1
if a < 0.0001:
break
print(b)
x = float(input())
fun(x)