开发者

SingPath Python Help - cosine problem

开发者 https://www.devze.com 2023-01-07 20:18 出处:网络
Any help? I have the following: import math def cosine (a): x = (a * math.pi) / 180 return math.cos(x) The problem:

Any help? I have the following:

 import math
 def cosine (a):
     x = (a * math.pi) / 180
     return math.cos(x)   

The problem: Create a function that calcul开发者_开发百科ates the cosine of an angle (in degrees). The math module contains a function math.cos that uses radians to calculate the cosine. You will need to convert the angle to radians first, then use the cos function to calculate cosine. Remember, you have to multiply the degrees by pi/180 to convert to radians.

Let me know! Am I using the cosine function wrong by using x as a parameter?


Your code as listed seems to work fine to me. If you want, you can omit the intermediate variable by just combining:

return math.cos((a * math.pi) / 180)
0

精彩评论

暂无评论...
验证码 换一张
取 消