错误的结果

问题描述 投票:-2回答:2

我的代码:

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

我的x是0.7071067811865475,结果是0到1之间的一些不规则数字,但据我所知,应该是45左右

python math sin
2个回答
2
投票

你用错误的函数转换错误的数字。

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

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


1
投票

math.radians转换为弧度,你想要math.degrees

它也在错误的地方,你正在转换一个数字,而不是一个角度。你要

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

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

© www.soinside.com 2019 - 2024. All rights reserved.