用Python编程:输入一个实数x,按下面方法计算COS(x)的结果, 上面公式中n计算到10即可(步长为2),结果精确到小数点后5位。输入考生本人学号的后3位整数(例如为203,为0.203),输出结果为多少。
import math
x=int(input("输入实数x:"))
x = x * 0.001
sum_up = 0
term = 1
i = 1
for j in range(11):
term = math.pow(-1,j) * math.pow(x,2*j) / math.factorial(2*j)
print(term)
sum_up += term
print ("%.5f"%sum_up)