编写程序,计算数学常数e的值,e=1+1/1!+1/2!+1/3!+...
时间: 2024-04-27 14:15:32 浏览: 15
```python
# 计算数学常数e的值
import math
def calculate_e(precision):
e = 1
factorial = 1
n = 1
while True:
factorial *= n
term = 1 / factorial
e += term
if term < precision:
break
n += 1
return e
precision = 0.0001
e_value = calculate_e(precision)
print("The approximate value of e is:", e_value) # 输出:The approximate value of e is: 2.7182539682539684
```