我是相當新的python,並試圖開發一個計算器。我已經創建了它,以便在你按9並退出之前一直詢問你的問題。我做了一個錯誤,而這樣做的,它一直要求我輸入第一個號碼並不斷循環,這Python計算器代碼
loop = 1
oper = 0
while loop == 1:
num1 = input("Enter the first number: ")
print num1
oper = input("+, -, *, /,9: ")
print oper
num2 = input("Enter the second number: ")
print num2
if oper == "+":
result = int(num1) + int(num2)
elif oper == "-":
result = int(num1) - int(num2)
elif oper == "*":
result = int(num1) * int(num2)
elif oper == "/":
result = int(num1)/int(num2)
elif oper == "9":
loop = 0
print "The result of " + str(num1) + str(oper) + str(num2) + " is " + str(result)
input("\nPress 9 to exit.")
修復壓痕請 – depperm