我試圖在蟒蛇一個簡單的計算器,但我似乎得到的輸入錯誤,每當我嘗試運行它:輸入錯誤
while True:
print("please choose one of these available options:\n\"add, subtract, multiply, divide, quit\"\ntype in exactly as shown or the calculator won't work");
choice = input();
if(choice == "quit"):
break;
elif(choice == "divide"):
num1 = float(input("Please enter a number:"));
num2 = float(input("Please enter another number:"));
output = num1/num2;
print("The answer is:", output);
elif(choice == "multiply"):
num1 = float(input("Please enter a number:"));
num2 = float(input("Please enter another number:"));
output = num1*num2;
print("The answer is:", output);
elif(choice == "subtract"):
num1 = float(input("Please enter a number:"));
num2 = float(input("Please enter another number:"));
output = num1-num2;
print("The answer is:", output);
elif(choice == "add"):
num1 = float(input("Please enter a number:"));
num2 = float(input("Please enter another number:"));
output = num1+num2;
print("The answer is:", output);
else:
print("Invalid Input. Try again");
當我運行代碼,解釋只是表明:NameError: name '...' is not defined
每當我輸入內容時(用輸入替換省略號)。
有人可以請看看我是否做了任何輸入錯誤,因爲這是唯一不行的。
謝謝
你用Python 3而不是Python 2運行代碼嗎? – TerryA
我認爲我的iPad的解釋器可能正在運行Python 2.7 –
這是你的問題。此代碼適用於python 3,但不適用於python 2.如果只能運行python 2.7,請將'input'更改爲'raw_input' – TerryA