8 作业:用户名密码 3次锁定
1:.基础需求
# 基础需求 _username = 'alex' _password = '123' count = 0 while count < 3: username = input('username:') password = input('password:') if username == _username and password == _password: print("----------Welcome %s-----"%username) break else: print('用户名或密码错误,请重新输入!') count += 1 else: print("-----you try more times------")
2.升级需求
# 升级需求 user_list = { 'alex':{'password':'123'}, 'jack':{'password':'123'}, } with open('lock', 'r') as f1: lock_user = f1.read() count = 0 while count < 3: username = input('请输入用户名:') if username == lock_user: print("用户名已经锁定") else: if username not in user_list: print("用户名不存在") else: password = input('请输入密码:') if password == user_list[username]['password']: print("欢迎%s"%username) break else: print("密码错误,请重新输入") count += 1 if count == 3: with open('lock', 'w') as f2: f2.write(username) else: print("----输入超过3次,用户被锁定---")
# bug:锁定的是第三次输入的用户名, # 锁定文件,直接覆盖, # 应该追加用户,如何实现?