Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 说出该名称时出错';数学';尝试使用asin()时未定义_Python - Fatal编程技术网

Python 说出该名称时出错';数学';尝试使用asin()时未定义

Python 说出该名称时出错';数学';尝试使用asin()时未定义,python,Python,我已经做了一个三坐标计算器(有点-它现在只使用正弦比),但我不能让它正常工作。我得到一个错误,说数学没有定义,当它应该得到线的长度。这是我的密码: 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

我已经做了一个三坐标计算器(有点-它现在只使用正弦比),但我不能让它正常工作。我得到一个错误,说数学没有定义,当它应该得到线的长度。这是我的密码:

    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

在使用数学之前,您需要导入数学,否则Python不知道您在说什么


一旦这样做,您将得到另一个错误:您的输入是字符串,您需要将它们转换为数字(使用
float()
),然后才能将它们作为参数传递给数学函数。同样,如果用户以度为单位输入角度,在将其传递到
asin
之前,您还需要将其转换为弧度。您需要导入数学模块:
导入数学
更正版本。你的数学也错了,但我没有做你所有的家庭作业;-)


它的意思正是它所说的。为什么您希望定义
math
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