import sys #被锁住用户 locked_name_list = {"zhangsan","lisi"} #正常用户 mtch_name_list = {"wangwu":"123456","maliu":"123456"} #输入匹配次数 match_count = 0 #允许输入的次数 match_limit = 3 while match_count < match_limit: flag = False user_name = input("请输入的用户名:") if len(user_name) == 0: print("用户名不为空!") continue for lock_name in locked_name_list: if lock_name == user_name: print("该用户被锁定!") break user_password = input("请输入密码:") for (match_name,match_password) in mtch_name_list.items(): if len(match_name) == 0: print("该系统还未有用户!") exit(); if match_name == user_name and match_password == user_password: print("欢迎登陆该系统!") exit() if match_name and match_password != user_password: if match_count < 2: match_count += 1 print("密码输入错误,请重新输入!") break else: print("登陆次数超过三次,该用户被锁定!") exit()