這是我的項目介紹:如何在Python中終止程序?
寫,顯示以下菜單的程序:
1)轉換到華氏攝氏度
2)轉換攝氏到華氏輸入1,2,或0退出:
在選項1和2的情況下,程序應該提示用戶輸入溫度,執行轉換並輸出結果。然後程序應該重新顯示菜單。當選擇選項0時,程序應該退出。
這是我到目前爲止有:
a = raw_input("1) Convert Fahrenheit to Celsius \n2) Convert Celsius to Fahrenheit \nEnter 1, 2, or 0 to exit: ")
x = raw_input("Enter degree: ")
y = float((x - 32)/1.8)
x = raw_input("Enter degree: ")
z = float((x + 32) * 1.8)
if a == 1:
print(y)
if a == 2:
print(z)
我怎樣才能終止這個程序?我在哪裏搞亂了?
嘗試'sys.exit()' –
作業?如果是這樣,你應該這樣標記它。 –
如果我沒有指出你的z方程應該是這樣的,我會覺得自己像個混蛋: z = float((x/1.8)+32) – Vorticity