Python“;或;语句语法不起作用?
我对python编程比较陌生,无论如何,这是一段较大代码的一小部分。这似乎引起了一些问题:Python“;或;语句语法不起作用?,python,Python,我对python编程比较陌生,无论如何,这是一段较大代码的一小部分。这似乎引起了一些问题: command = input("Command: ") while command != ("Exit lift" or "Up" or "Down" or "1" or "2" or "3" or "Cycle"): print("Error: Command entered doesn't match the 'Commands' list, or isn't a possible com
command = input("Command: ")
while command != ("Exit lift" or "Up" or "Down" or "1" or "2" or "3" or "Cycle"):
print("Error: Command entered doesn't match the 'Commands' list, or isn't a possible command at this time! Please try again...")
command = input("Command: ")
print ("Works")
基本上,我测试了这些命令,它只接收“退出提升”命令和“向上”、“向下”、“1”等。不行
有什么建议吗?初学者(“退出提升”或“上升”或“下降”或“1”或“2”或“3”或“循环”)
评估为退出提升“
>>> ("Exit lift" or "Up" or "Down" or "1" or "2" or "3" or "Cycle")
'Exit lift'
所以命令!=(“退出提升”或“上升”或“下降”或“1”或“2”或“3”或“循环”):
相当于命令!=(“出口电梯”)
按顺序使用不在中:
while command not in ("Exit lift", "Up", "Down", "1", "2", "3", "Cycle"):
....
(“退出提升”或“上升”或“下降”或“1”或“2”或“3”或“循环”)
计算为“退出提升”
>>> ("Exit lift" or "Up" or "Down" or "1" or "2" or "3" or "Cycle")
'Exit lift'
所以命令!=(“退出提升”或“上升”或“下降”或“1”或“2”或“3”或“循环”):
相当于命令!=(“出口电梯”)
按顺序使用不在中:
while command not in ("Exit lift", "Up", "Down", "1", "2", "3", "Cycle"):
....
而不是
while command != ("Exit lift" or "Up" or "Down" or "1" or "2" or "3" or "Cycle"):
你应该使用
while not command in ("Exit lift", "Up", "Down", "1", "2", "3", "Cycle"):
而不是
while command != ("Exit lift" or "Up" or "Down" or "1" or "2" or "3" or "Cycle"):
你应该使用
while not command in ("Exit lift", "Up", "Down", "1", "2", "3", "Cycle"):
您可以使用数组,并在
单词中使用
allowed = ["Exit lift", "Up", "Down", "1", "2", "3", "Cycle"]
while command not in allowed:
print "not allowed!"
print "works"
您可以使用数组,并在
单词中使用
allowed = ["Exit lift", "Up", "Down", "1", "2", "3", "Cycle"]
while command not in allowed:
print "not allowed!"
print "works"
我正要发布同样的答案:)谢谢,你的答案很有帮助,也很简单。干杯。我正要发布同样的答案:)谢谢,你的答案很有用,也很简单。干杯