我在接受用户输入时遇到了一个奇怪的问题,在列表中添加了正确的信息,并检查列表中是否有正确的输入
出于某种原因,只输入'pally'调用end_instance.enter()
(不带'polly')
def enter(self):
print """Please enter your two passwords to proceed. Check the other doors for answers. You have five guesses."""
green_count = 0
green_ans = []
while green_count < 5:
green_guess = (raw_input('> '))
if 'polly' or 'pally' in green_guess:
green_ans.append(green_guess)
green_count += 1
if 'polly' and 'pally' in green_ans:
print "cool"
end_instance.enter()
else:
print "try again"
green_count += 1
'polly'
和'pally'
都是非空字符串,因此等同于 ^Python中布尔上下文中的{or
和and
计算 带短路计算的布尔表达式:因此,该行:
相当于说:
因此,只有
'pally'
起作用'polly'
将始终为真因此,请将代码更改为:
相关问题 更多 >
编程相关推荐