私のコードは華氏を摂氏に変換しています。これだよ。TryとExceptブロックを使用しますが、Exceptパートには定義されていませんPython
def again():
calc = raw_input("Press y to convert again. Press n to quit. ").lower()
if calc == "y":
main()
elif calc == "n":
quit()
else:
again()
def main():
fahrenheit = input("What do you want to convert from Fahrenheit to Celsius? ")
try:
celsius = (fahrenheit - 32) *5/float(9)
print('%0.2F degree Celsius is equal to about %0.1f degree Fahrenheit' %(celsius,fahrenheit))
again()
except ValueError:
print("That is not a number")
check()
実行する場合は、変換する数値の代わりに文字を入力します。 Exceptビットは実行されませんが、文字は定義されていません。 fahrenheit = input("What do you want to convert from Fahrenheit to Celsius? ")
を行った場合、引用符で囲まれた数字を引用符なしの通常の数字に変換するにはどうすればよいですか?私はValue Error
を選んだからだと思いますが、私は考えていません。どんな助けもありがとう!
エラーを表示してください。 – cco