from math import fabs
from decimal import decimal
x = decimal(input('input a number x='))
n = 1
sinx = x/1
a = x/1
fenmu = 1
while fabs(sinx)>= 1e-8:
n+=1
n = (2*n-1)
fenmu = fenmu/(n*(n-1))
a = a*(x**2)*fenmu*(-1)
sinx += a
if fabs(sinx)< 1e-8:
print(sinx)
不能import decimal,如果不用decimal而用float的话,对输入的数字,会报错int too large to convert to float