4

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
4

3 に答える 3

8

使用する前に必要import mathです。そうしないと、Python は何について話しているのかわかりません。

これを行うと、別のエラーが発生します。入力は文字列であり、float()数学関数に引数として渡す前に、( を使用して)数値に変換する必要があります。nye17が指摘したように、ユーザーが角度を度単位で入力した場合は、それを に渡す前にラジアンに変換する必要もありますasin

于 2012-05-20T20:24:23.050 に答える
3

修正版。あなたの数学も間違っていますが、私はあなたのすべての宿題をやっているわけではありません ;-)

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
于 2012-05-20T20:27:08.697 に答える
2

math モジュールをインポートする必要があります。import math

于 2012-05-20T20:25:24.330 に答える