【发布时间】:2014-01-20 21:52:43
【问题描述】:
variable1 = 0
while variable1 != "1" or variable1 != "2" or variable1 != "3":
variable1 = input ("Enter variable1: ")
print("Succes")
即使变量被赋值为 1 或 2 或 3,我的代码也永远不会退出 while 循环。 我在这里遗漏了什么或做错了什么?我从来没有读过任何关于 Python 的文档说 or 语句在 while 循环中不起作用。根据命题演算,这应该是正确的,因为 True or False or False = True
顺便说一下,我知道我没有使用整数。
提前致谢!
【问题讨论】:
-
!= to在那里做什么? 杀了to!杀死to!杀死to! 不祥的诵经> -
当 variable1 = 'al;dfjakl;fkja;lkajdfj' 时会发生什么?
-
variable1 != to "1"是语法错误。为什么里面有“to”? -
@inspectorG4dget 那不应该在那里,我犯了一个奇怪的错字。我会解决的。
-
@Joe 那会是假的,不行,再次要求输入。
标签: python loops while-loop logic