我对 Python 还是很陌生,对我正在开发的程序发生了什么感到困惑。代码如下。问题是代码从不运行任何 if/elif/else 行。它只是不断循环菜单和输入。我正在使用 3.2。
# 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!")
PS - 这是我在这里的第一篇文章,所以如果我做的不好,请告诉我。
谢谢!
捷通