2016-09-24 5 views
-1

私は宿題を解決しようとしています。私は2つの入力に基づいてラダーの長さを計算するプログラムを書く必要があります。はしごを壁に向かって傾けることによって作られた角度。三角法:sin(x)負の値を得る

私は、度をラジアンに変換するには、次の式を使用:

radians = (math.pi/180) * x # x is the given angle by the user. 

私はその機能を使用するだけでなく数学ライブラリをインポートしました。

def main(): 

    import math 

    print("this program calculates the length of a ladder after you give the height and the angle") 

    h = eval(input("enter the height you want to reach using the ladder")) 
    x = eval(input("enter the angle which will be created be leaning the ladder to the wall")) 

    radians = (math.pi/180) * x 

    length = h/math.sin(x) 

    print("the length is:", length) 


main() 

私は間違っていますか?
コードが不足していることが分かり、誰かがギャップを埋める手助けをすることができれば感謝します。

+0

'eval'を使用しないでくださいです。あなたは 'float'値が必要なことを知っていますので、' h = float(input( "...")) 'を使用してください。 – chepner

+0

BTW:角度を変換するには、 'math.radians(x)'と 'math.degrees(y)'を使用します。 – Bakuriu

+0

フロートポイントへの私の関心をつかんでくれてありがとう。 ところで、宿題の質問を貼り付けて解決するための援助を求めるのはo.kですか?それとも削除されますか? – Donello

答えて

1

計算後にradiansを使用したことはありません。

すなわちlength = h/math.sin(radians)

0

crickt_007の正しい答えは絶対に明確にする:あなたは、それは正弦の引数でなければなりません算出した後、あなたが使用しなかったradians:あなたはradians計算

length = h/math.sin(radians) 
+0

ありがとうございました。それは私のためにそれを固定した。 – Donello

0

は、[OK]をthatsの、しかし問題はそれを使用したことはないradians値。私は次のようにコードを変更しなければならないと思います:)

def main(): 

    import math 

    print("this program calculates the length of a ladder after you give the height and the angle") 

    h = eval(input("enter the height you want to reach using the ladder")) 
    x = eval(input("enter the angle which will be created be leaning the ladder to the wall")) 

    radians = (math.pi/180) * x 

    length = h/math.sin(radians) 

    print("the length is:", length) 


main() 

ご入力の両方が5になる場合、出力はthe length is: 57.36856622834928

関連する問題