valid = False count = 3 passwdList = [1] while count > 0: input = raw_input("enter password") for eachPasswd in passwdList: if input == eachPasswd: valid = True break if not valid: # (or valid == 0) print "invalid input" count -= 1 continue else: break