首页 > 解决方案 > While 循环(非常简单)

问题描述

我正在处理下面的代码,我想要or ,但它一直在 while 循环中运行temp12

temp = input("1 for yes/2 for no")
while (temp!="1" or temp!="2"):
    print("please input 1 or 2")
    temp = input("1 for yes/2 for no")
print(temp)

标签: pythonpython-3.xloopswhile-loop

解决方案


改变这个:

while temp!="1" or temp!="2":

对此:

while temp!="1" and temp!="2":

推荐阅读