我知道这是行不通的,但是有什么解决方案,而不是为每个选项重复底部?问题是continue
和break
不能放在def
while True:
print (" For + press A,- press B,X press C,/ press D\n")
choice = input ("Enter either A,B,C or D \n").title()
number1 = int(input ("Now enter the first number(s) of the calculation\n"))
number2 = int(input ("Now enter the second number(s) of the calculation\n"))
if choice == "A":
print (number1,"+",number2,"=",(number1+number2))
again()
elif choice == "B":
print (number1,"-",(number1-number2))
again()
elif choice == "C":
print (number1,"X",(number1*number2))
again()
elif choice == "D":
if number2 == 0:
print("Error")
print (number1,"/",(number1/number2))
again()
else:
print ("Error!")
again()
def again():
con = input ("Do you want to continue Y or N?".title())
if con =="Y":
continue
else:
break