python之路day1 作业
作业二:编写登陆接口
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
user-pass.json
内容: {"can":"123"}
1 import json 2 3 with open('user-pass.json') as f: 4 a = json.loads(f.read()) 5 count = 0 6 while True: 7 name = input('pls user: ').strip() 8 with open('black.txt') as fb: 9 c = [b.strip() for b in fb.readlines() ] 10 if name not in a: 11 print('user not found!0.0') 12 elif name in c: 13 print('账号被锁定!') 14 else: 15 while count < 3: 16 pwd = input('pls pass:').strip() 17 if pwd == a.get(name): 18 print('登录成功') 19 break 20 else: 21 print('密码错误') 22 count += 1 23 else: 24 print('错误三次,账号已被锁定') 25 with open('black.txt','a') as fbb: 26 fbb.write(name + '\n') 27 else: 28 print('错误三次!')

浙公网安备 33010602011771号