第6章函数-5 使用函数求余弦函数的近似值 import math def fac(n): res = 1 for i in range(1, n + 1): res *= i return res def funcos(eps, x): res = 0 flag = 1 cnt = 0 while True: q = flag * math.pow(x, cnt) / fac(cnt) if abs(q) < eps: break res += q if flag == 1: flag = -1 else: flag = 1 cnt += 2 return res