我對Python仍然很陌生,對於我正在開發的程序發生了什麼感到困惑。代碼如下。問題是代碼從不運行任何if/elif/else行。它只是讓菜單和輸入循環。我使用3.2。雖然Python循環無法正常工作(初學者)
# Program to Add, Subtract, Multiply, and Divide
def printmenu():
print("Calculator v0.01")
print("[A]dd Two Numbers")
print("[S]ubtract Two Numbers")
print("[M]ultiply Two Numbers")
print("[D]ivide Two Numbers")
print("[Q]uit the Program")
choice = "x"
while choice.lower != "q":
printmenu()
choice = input("What would you like to do? ")
firstnum = input("What is the first number? ")
secnum = input("What is the second number? ")
if choice.lower == "a":
print("The answer is ", (firstnum + secnum))
elif choice.lower == "s":
print("The answer is ", (firstnum - secnum))
elif choice.lower == "m":
print("The answer is ", (firstnum * secnum))
elif choice.lower == "d":
print("The answer is ", (firstnum/secnum))
else:
print("Choice not recognized. Try again!")
P.S. - 這是我在這裏的第一篇文章,所以如果我沒有做好正確的事情,請讓我知道。
謝謝!
JT
您的帖子很好 - 您的問題標題指示帖子的內容/您想要回答的內容,您提供的代碼不工作,您說什麼不工作以及您期望發生什麼。 – Patashu 2013-04-20 11:24:10