代码:
def func(a,isEnd=0): sum=1.0 if isEnd==1: i=1 t=1 while t>10**-4: t=1 for j in range(1,i+1): t=t/j sum=sum+t i=i+1 return sum else: for i in range(1,a): t=1.0 for j in range(1,i+1): t=t/j sum=sum+t return sum if __name__=="__main__": print(func(50)) print(func(1,1,))
运行结果:
2.7182818284590455 2.71827876984127