import math
def custom_exp(x):
result = 1.0
term = 1.0
n = 1
while abs(term) > 1e-10: # 设置一个终止条件
term *= (x / n)
result += term
n += 1
return result
# 测试自定义的 exp 函数
x = 2.5
print(custom_exp(x)) # Output: 12.182493960703473
# 使用 math 库中的 exp 函数进行对照
print(math.exp(x)) # Output: 12.182493960703473