我有这个代码:
choose = ""
while choose != "x" or choose != "X" or choose != "o" or choose != "O":
choose = input("X or O? -> ")
但是即使用户插入x,X,o或O,它也会继续。
我是编码方面的新手,有谁想让它起作用?
尝试一下
while choose not in [ "x" , "X" , "o" ,"O"]:
4个条件中的任何一个变为真都会继续循环。您可以使用由“或”表示的“和”。
相反,尝试使用Python的'in','not in'关键字。
逻辑组合不是您想要的。[在此处输入图片描述] [1]如果输入O
作为选择,则条件choose != "x"
为真,则while循环。
我想你想要的是:
choose = ""
while not(choose == "x" or choose == "X" or choose == "o" or choose == "O"):
choose = input("X or O? -> ")
有效〜/:D