未收到 python 数学代码的正确输出
Not recieving correct output from python math code
知道为什么以下代码会产生错误的计算吗?这可能只是语法不正确。
import math
ax = distance1 * math.cos(direction1)
distance1
设置为 7600。
并且 direction1
设置为 113。
在普通计算器中,113的余弦乘以7600等于-2969.556576518480538.
但是上面的代码会产生 7564.02643525
.
math.cos
等三角函数take arguments in radians,不是度数。您可以使用math.radians
进行转换。
ax = distance1 * math.cos(math.radians(direction1))
这会按预期生成 -2969.5565765184806
知道为什么以下代码会产生错误的计算吗?这可能只是语法不正确。
import math
ax = distance1 * math.cos(direction1)
distance1
设置为 7600。
并且 direction1
设置为 113。
在普通计算器中,113的余弦乘以7600等于-2969.556576518480538.
但是上面的代码会产生 7564.02643525
.
math.cos
等三角函数take arguments in radians,不是度数。您可以使用math.radians
进行转换。
ax = distance1 * math.cos(math.radians(direction1))
这会按预期生成 -2969.5565765184806