python cos(x) 精确到某值 esp如0.00001

cos(x)

import math
def funcos(esp, x):
    x = float(x)
    c1 = float(1)
    c2 = float(0)
    y = 1
    z = 2
    while(math.fabs(c1) > esp):
        c2 += c1
        c1 = (-1)*c1*x*x/y/z
        y += 2
        z += 2
    c2 += c1
    print(c2)
esp = float(input('请输入esp:'))
x = float(input('请输入x:'))
funcos(esp, x)

你可能感兴趣的:(python,开发语言)