0

私はPythonが初めてで、華氏を摂氏に変換するかどうかを選択するPythonプログラムを作成しようとしています。プログラムは次のとおりです。

x = (raw_input("would you like to convert fahrenheit(f) or celsius(c)?"))
if x == "f":
 y = (raw_input("what is the fahrenheit?"))
 f = (int(y) - 32) * 5.0 / 9
print f

if x == "c":
 n = (raw_input("what is the celsius?"))
 z = (int(n) *9) / 5 + 32
 print "and in fahrenheit, that is:"
 print z

に変更しようとしましif x == "c"elif x == "c"が、 になりましたTextError。何か案は?

4

4 に答える 4

1

簡単な方法は次のとおりです。

x = (raw_input("would you like to convert fahrenheit(f) or celsius(c)? "))
if x == "f":
    y = (raw_input("what is the fahrenheit?"))
    f = (int(y) - 32) * 5.0 / 9
    print "and in celsius, that is: ",
    print f
elif x == "c":
    y = (raw_input("what is the celsius?"))
    f = (int(y) *9) / 5.0 + 32
    print "and in fahrenheit, that is: ",
    print f
else
    print "Error"
于 2013-05-20T03:29:33.813 に答える
-1

以下を実行してください(「def cel_fah(C):」も含めてください)

def cel_fah(C):

'''
Takes in temps in celsius and gives them out in fahrenheit
'''

F=abs(C*9/5+32)

print(f'{C}°celsius is equal to {F}° fahrenheit')

次に、関数を簡単に呼び出して、今のように結果を取得できます( () で摂氏の数値を渡すことができます)

{度記号 (°) には、alt+248 を使用できます}

cel_fah(0)

摂氏 0° は華氏 32.0° に等しい

私が助けになれたことを願っています。;)

于 2018-06-24T12:05:21.297 に答える