由于某种原因,当我键入“ exit”或“ EXIT”时,循环会继续迭代
我尝试使用变量和break语句中断
obj = 1
while obj != None:
a = input("enter a number:\n")
b = input("enter a number:\n")
try:
int(a)
int(b)
print("succes!")
except ValueError:
print("you didnt enterd numbers")
continue
print("what do yo want to do?\n")
donxt = input("for exit the program type EXIT, to continue tap CONTINUE:\n")
if donxt == "continue" or "CONTINUE":
continue
elif donxt == "EXIT" or "exit":
obj = None
答案 0 :(得分:3)
您有if donxt == "continue" or "CONTINUE"
这实际上是if (donxt == "continue") or ("CONTINUE")
而不是if (donxt == "continue") or (donxt == "CONTINUE")
。
"CONTINUE"
始终取值为true
,因此(donxt == "continue") or ("CONTINUE")
始终为true。
您要执行以下操作:
if (donxt == "continue") or (donxt == "CONTINUE")