import math
def funcos(eps, x):
result = 0 # 初始化结果
n = 0 # 从第0项开始
while True:
# 计算当前项的值
term = ((-1) ** n) * (x ** (2 * n)) / math.factorial(2 * n)
# 如果当前项的绝对值小于eps,退出循环
if abs(term) < eps:
break
# 累加到结果中
result += term
n += 1 # 下一项
# 返回结果,保留4位小数
return round(result, 4)
测试样例
eps, x = input().split()
eps, x = float(eps), float(x)
value = funcos(eps, x)
print("cos({0}) = {1:.4f}".format(x, value))