Ask your own question, for FREE!
Computer Science 23 Online
OpenStudy (anonymous):

I have programmed a maths program in python but the only problem is with the trigonometry section that some answers need to be in degrees and not radians. How do I convert into degrees? I have tried x = input("value: ") y = math.degrees(x) #gives me the wrong answer and: x = input("input: ") y = x*180/math.pi #still wrong output

OpenStudy (anonymous):

Please post a test case,with wrong output and desired output.

OpenStudy (anonymous):

math.cos(x) =>length of the adjacent side of the right triangle inscribed in a circle with angle x radians

OpenStudy (anonymous):

math.radians(x) =>returns radians 1 deg => 0.01745 rad 1 rad =>57.30659 deg

OpenStudy (amistre64):

180 degrees is the same measure as pi radians; so the conversion you have set up is good; 180 x radians * ----- = degrees pi the logic of course being that you divide out the pi and stretch it to fit the degrees.

OpenStudy (amistre64):

How are you determining the value attributed to the input of 'x' ? if that value is off, it would produce erroneous results :)

OpenStudy (anonymous):

This: def cosine(): print ' ' b = input(90) x = math.cos(b) y = math.degrees(x) print ' ' return y Returns: -25.6727271154 and def cosine(): print ' ' b = input(90) x = math.cos(b) y = x*(180/math.pi) print ' ' return y returns the same value pure radians is def cosine(): print ' ' b = input(90) x = math.cos(b) print ' ' return x returns: -0.448073616129

OpenStudy (anonymous):

Input is actually the angle that the user inputs but for all of these I have just used 90

OpenStudy (amistre64):

if your input is in degrees; change it to radians before passing it thru the function and see how that helps :) In javascript, the input is read AS radians to begin with. b = 90*Math.PI/180 x = Math.cos(b) Might help :)

OpenStudy (amistre64):

In that little tidbit; the raw input is translated as radians ...

OpenStudy (amistre64):

this is the revised version that converts the input into radians; calcultaes the cosine, and then converts it back as degrees...

OpenStudy (anonymous):

The answer that gives me is: 6.12323399574e-17

OpenStudy (anonymous):

the cos of 90 is not 6.12323399574e-17 as far as I know it's 0

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!