用python写从键盘输入x的值,求, 直到最后一项绝对值小于le−7(即10−7)为止(注:x为弧度值
时间: 2024-05-22 14:17:00 浏览: 26
python如何求绝对值教程.pptx
import math
x = float(input("请输入x的值(弧度制):"))
result = 0
n = 0
while True:
term = ((-1) ** n) * (x ** (2 * n + 1)) / math.factorial(2 * n + 1)
result += term
n += 1
if abs(term) < 10 ** (-7):
break
print("sin(x)的值为:", result)
阅读全文