Python 我的用户输入测试与一个输入正确匹配,但与其他输入不匹配
如果他们不输入Python 我的用户输入测试与一个输入正确匹配,但与其他输入不匹配,python,python-3.x,Python,Python 3.x,如果他们不输入'I'或'integer'我想做这件事,它会转到说不是游戏==“I”或游戏==“integer”的部分。每当我输入I时,它就会工作,但当我输入integer时,它就不工作了。您需要在或条件周围加上括号: while True: game = input("Would you like to play: Guess the integer(i) or true/false(t). **Case Senestive** ") if not name.isalpha():
'I'
或'integer'
我想做这件事,它会转到说不是游戏==“I”或游戏==“integer”
的部分。每当我输入I
时,它就会工作,但当我输入integer
时,它就不工作了。您需要在或
条件周围加上括号:
while True:
game = input("Would you like to play: Guess the integer(i) or true/false(t). **Case Senestive** ")
if not name.isalpha():
print (name, "Enter the correct values")
continue
if not game == "i" or game == "t" or game=="integer" or game=="true/false":
print ("Enter i, integer or true/false, t")
continue
else:
break
否则Python会将其视为(而不是game==“i”)或…
您最好在电视上使用而不是:
if not (game == "i" or game == "t" or game=="integer" or game=="true/false"):
这不仅更短,而且更快;只进行一次检查,而不是对每个字符串进行单独的=
测试。请将代码作为文本输入问题。您可以高亮显示它,然后按Ctrl-k以保持格式良好。我已编辑了原始帖子,并包含了代码:)谢谢您的帮助:)
if game not in {"i", "t", "integer", "true/false"}: