valid = False
count = 3
passwdList = [111,2222,33333,44444]
while count > 0:
input = raw_input('enter password:')
for eachPasswd in passwdList:
if input == eachPasswd:
valid = True
break
if not valid:
print 'invalid input'
count -= 1
continue
else:
count = 3
passwdList = [111,2222,33333,44444]
while count > 0:
input = raw_input('enter password:')
for eachPasswd in passwdList:
if input == eachPasswd:
valid = True
break
if not valid:
print 'invalid input'
count -= 1
continue
else:
break
这是让用户有3次机会输入正确的密码,如果失败的话,那么valid就为一个假值,我们就可以阻止用户继续猜测密码。
但是我实现之后不管我输入司马值,他都显示了我是失败的,我输入passwdList中的正确密码也被提示是错误的 我很费解啊 有大牛帮着解释下吗?