在尝试使用asin()时未定义名称'math'时出错

Rya*_*ner 4 python

我已经制作了一个Trignometric计算器(种类 - 它只使用现在的正弦比),但我不能让它正常工作.我得到一个错误,表示数学未定义时应该得到该行的长度.这是我的代码:

    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
Run Code Online (Sandbox Code Playgroud)

Dou*_*gal 8

你需要import math先使用它 - 否则Python不知道你在说什么.

一旦你这样做,你将得到另一个错误:你的输入是字符串,你需要将它们转换为数字(with float()),然后才能将它们作为参数传递给数学函数.正如nye17所指出的,如果用户以度为单位输入角度,您还需要在传递之前将其转换为弧度asin.