Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error saying that name 'math' is not defined when trying to use asin()

Tags:

python

I have made a Trignometric calculator (Kind of - it only uses the sine ratio as of now) but I can't get it to work right. I get an error that says math is not defined when it's supposed to get the length of the line. Here is my code:

    trig = raw_input ('What are you looking for? A) I have the opposite, and I want the        Hypotenuse. ')
    if trig.lower() == 'a':
        ang = raw_input ('Please enter the measure of the angle you have ')
        line = raw_input ('Please enter the length of the opposite! ')
        math.asin (ang)*line
like image 597
Ryan Werner Avatar asked Dec 13 '22 02:12

Ryan Werner


1 Answers

You need to import math before you can use it -- otherwise Python doesn't know what you're talking about.

Once you do that, you'll get another error: your inputs are strings, and you need to convert them to numbers (with float()) before you can pass them as arguments to math functions. As nye17 pointed out, if the user inputs the angle in degrees, you'll also need to convert it to radians before passing it to asin.

like image 148
Danica Avatar answered May 21 '23 06:05

Danica