_flag = False
count = 0
users = [['ziv', '123'], ['alex', '12345']]
while count < 3:
username = input('Username:')
password = input('Password:')
for user_item in users:
if username == user_item[0] and password == user_item[1]:
print('登陆成功')
_flag = True # 登陆成功flag改为True
break # 用来跳出for循环
else:
print('用户名或密码错误') # for循环正常执行完(登录成功会被break,不会执行else,反之执行),再执行else
if _flag:
break # 用来跳出while循环
count += 1
else:
print('用户名或密码错误超过三次!') # 登录成功while被break,不会执行else,反之执行