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)
精彩评论