【发布时间】:2016-04-10 14:28:27
【问题描述】:
当 var[5] 从 "" 变为 "left" 或 "right" 时,while 循环不会停止
#Variable Input
name = input("Enter your name: ")
place = input("Enter where you live: ")
sex = input("Are you a boy (Y/N): ")
scaryanimal = input("Enter the type of animal that you are most scared of: ")
happyanimal = input("Enter your favourite type of animal: ")
var=[name,place,sex,scaryanimal,happyanimal,""]
#Main story
#Other code goes here
#Offending While loop
while var[5].lower() != "left" or var[5].lower() != "right":
var[5] = input("Did he go left or right: ")
print(var[5])
【问题讨论】:
-
我看不出你在哪里改变
var[5]。如果你认为vari = input(...)改变了var的内容,你可能误解了列表赋值的语法。 -
糟糕,刚刚意识到我忘记用 var[5] 替换 vari,我将 var[5] 更改为一个变量,以检查它是否是错误的数组。 :-(
-
您的原始代码是否“正确”使用
var[5]而不是vari?
标签: python loops python-3.x while-loop