如何使用Python将弧度转换为度? [英] How can I convert radians to degrees with Python?
问题描述
在 数学
模块中,仅找到带有cos/sin/tan/acos/asin/atan的 math.cos(x)
.这将以弧度返回答案.我怎样才能得到度数的答案?
In the math
module, I could only find math.cos(x)
, with cos/sin/tan/acos/asin/atan. This returns the answer in radians. How can I get the answer in degrees?
这是我的代码:
import math
x = math.cos(1)
y = x * 180 / math.pi
print(y)
30.9570417874
我的度数计算器给我:
cos(1)
0.9998476...
推荐答案
Python在 math
包中包含两个函数;radians
将度数转换为弧度,degrees
将弧度转换为度数.
Python includes two functions in the math
package; radians
converts degrees to radians, and degrees
converts radians to degrees.
要匹配计算器的输出,您需要:
To match the output of your calculator you need:
>>> math.cos(math.radians(1))
0.9998476951563913
请注意,所有的三角函数都在角度和三角形两侧的比率之间转换.cos,sin和tan以弧度表示的角度作为输入并返回比率;acos,asin和atan以比率作为输入,并返回以弧度表示的角度.您只转换角度,而不转换比例.
Note that all of the trig functions convert between an angle and the ratio of two sides of a triangle. cos, sin, and tan take an angle in radians as input and return the ratio; acos, asin, and atan take a ratio as input and return an angle in radians. You only convert the angles, never the ratios.
这篇关于如何使用Python将弧度转换为度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!