An error indicating the name "math" is not detected when trying to use asin ()

I made a trigonometric calculator (look - it uses the sine ratio only now), but I can not get it to work correctly. I get an error message that says math is not defined when it is supposed to get the length of a string. 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 
+4
source share
3 answers

You need to import math before you can use it, otherwise Python does not know what you're talking about.

Once you do this, you will get another error: your inputs are strings, and you need to convert them to numbers (using float() ) before you can pass them as arguments for mathematical functions. Since nye17 indicated if the user enters the angle in degrees, you will also need to convert it to radians before passing it to asin .

+8
source

Fixed version. Your math is wrong too, but I'm not doing all the homework; -)

 import math trig = raw_input ('What are you looking for? A) I have the opposite, and I want the Hypotenuse. ') if trig.lower() == 'a': ang = float(raw_input ('Please enter the measure of the angle you have ')) line = float(raw_input ('Please enter the length of the opposite! ')) print "answer is", math.asin(ang)*line 
+3
source

You need to import the math module: import math

+2
source

Source: https://habr.com/ru/post/1413432/


All Articles