结果错误

时间:2018-09-06 15:31:02

标签: python math sin

我的代码:

import math
x = input()
print(math.asin(math.radians(float(x))))

我的x为0.7071067811865475,结果是0到1之间的某个无理数。但是据我所知,它应该在45左右。

2 个答案:

答案 0 :(得分:2)

您使用错误的函数转换了错误的数字。

>>> import math
>>> x = 0.7071067811865475
>>> math.degrees(math.asin(x))
44.99999999999999
>>>

也就是说,给定x(这是一个角度的正弦),调用asin以计算该角度(以弧度为单位),然后使用degrees将该角度转换为度

答案 1 :(得分:1)

math.radians转换为弧度,您需要math.degrees

它也在错误的位置,您要转换的是数字,而不是角度。您要

print(math.degrees(math.asin(float(x))))

https://docs.python.org/3/library/math.html#angular-conversion