2013-05-19 107 views
0

我一直在Python 3.3.1版本的這個基本計算器程序中出現錯誤。我自己找不到問題,有人可以幫我嗎?非常感謝您提前!爲什麼在編譯單個語句錯誤時發現多個語句? (Python)

x=(input("Which operation would you like to perform?")) 
     if x=='Addition': 
     y=int(input("Enter the first number?")) 
     z=int(input("Enter the second number?")) 
     a=y+z 
     print(a) 
    elif x=='Subtraction': 
     y=int(input("Enter the first number?")) 
     z=int(input("Enter the second number?")) 
     a=y-z 
     print(a) 
    elif x=='Multiplication': 
     y=int(input("Enter the first number?")) 
     z=int(input("Enter the second number?")) 
     a=y*z 
     print(a) 
elif x=='Division': 
     y=int(input("Enter the first number?")) 
     z=int(input("Enter the second number?")) 
     a=y/z 
     print(a) 
+1

你能發佈錯誤嗎? – Don

+1

什麼是錯誤 – Rajeev

+0

錯誤只是說「SyntaxError:編譯單個語句時發現多個語句」 它在第一行「x =(input(」您想要執行哪種操作?「))」 – user2399322

回答

0

你的選項卡搞砸了,我認爲,嘗試這樣的事情:

x=input("Which operation would you like to perform?") 
if x=='Addition': 
    y=int(input("Enter the first number?")) 
    z=int(input("Enter the second number?")) 
    a=y+z 
    print(a) 
elif x=='Subtraction': 
    y=int(input("Enter the first number?")) 
    z=int(input("Enter the second number?")) 
    a=y-z 
    print(a) 
elif x=='Multiplication': 
    y=int(input("Enter the first number?")) 
    z=int(input("Enter the second number?")) 
    a=y*z 
    print(a) 
elif x=='Division': 
    y=int(input("Enter the first number?")) 
    z=int(input("Enter the second number?")) 
    a=y/z 
    print(a) 
+0

即使使用製表符更正,我仍然會得到相同的錯誤 – user2399322

+0

@ user2399322我逐字複製/粘貼了此答案的代碼塊,它適用於我。 – Aya

+0

@Aya你使用閒置的python gui嗎?你在版本3.3.1? – user2399322

-1

x= raw_input("Which operation would you like to perform?")將解決烏爾問題

編輯:Python 3中的raw_input更名爲輸入()來獲取舊行爲使用eval(input(....))參考http://docs.python.org/3.0/whatsnew/3.0.html#builtins

希望這會有所幫助

+0

的raw_input使用給我一個回溯 回溯(最近通話最後一個)「的SyntaxError在編譯一個語句中找到多條語句」: 文件「」,1號線,在 X的raw_input =( 「你想要執行哪種操作?「) NameError:name'raw_input'未定義 – user2399322

+0

'raw_input'在Python 3中不存在。 – Blender

相關問題