tag =Truewhile tag:
user =input('请输入您的用户名:')
pwd =input('请输入您的密码:')withopen('users.txt', mode='rt', encoding='utf-8')as a:for i in a:
name, password = i.strip().split(':')if user == name and pwd == password:print('登入成功','''
输入指令:
'q':退出
''')while tag:
res =input('请输入指令:').strip()if res =='q':print('已退出')
tag =Falseelse:print('请输入正确的指令')breakelse:print('账号或密码错误,请重新输入')
2、需求升级,同一用户输出三次锁定他
# 要求升级,同一用户输出三次锁定他# 文档内容:# sailan:200024:0# egon:123:0# tank:123:0# ^ 用于记录登入次数
tag =True
user_info ={}while tag:
user =input('请输入您的用户名:')
pwd =input('请输入您的密码:')withopen('users.txt', mode='rt', encoding='utf-8')as a:for i in a:
name, password, count = i.strip().split(':')
user_info.setdefault(name,[password,int(count)])for r in user_info:if user_info[r][1]>3:# 判断计数,若大于3则不给他登入print('账号已被锁定')breakelif user == r and pwd == user_info[r][0]:print('登入成功','''
输入指令:
'q':退出
''')while tag:
res =input('请输入指令:').strip()if res =='q':print('已退出')
tag =Falseelse:print('请输入正确的指令')breakelse:print('账号或密码错误,请重新输入')if user in user_info:# 判断用户输入的用户名是否在库里
user_info[user][1]+=1# 错误则当前账号计数加一
帅兰tag = Truewhile tag: user = input('请输入您的用户名:') pwd = input('请输入您的密码:') a = (open('users.txt', mode='rt', encoding='utf-8')) for i in a: name, password = i.strip().split(':') if user == name and pwd == password: