python求e近似值怎么算?
ython編程 求e的近似值
def f(x,n):
s=1
for i in range(1,n+1):
s=s*i
a=1/s
return a
def e(n):
s=1
if n<=0:
print('不符合要求')
elif n>1000:
print('不符合要求')
elif isinstance(n,float):
print('不符合要求')
else:
for i in range(1,n+1):
s=f(i,i)+s
print('%.8f'%s)
if __name__=='__main__':
n=int(input('請(qǐng)錄入飛負(fù)正數(shù)<=1000\n'))
e(n)