views:

33

answers:

1

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 calculates 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?

A: 

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)
Amber
Thanks. That seemed to work.