1 # -*- coding:utf-8 -*- 2 __author__ = 'admin' 3 ''' 4 locked.txt: 5 liuxiaoyu 6 xiaodong 7 tenglan 8 match.txt: 9 alex 123456 10 xiaoyu 6543210 11 wulongyuan 6667770 12 ''' 13 import sys 14 15 account_file = 'c:\python作业\day1\match.txt' 16 locked_file = 'c:\python作业\day1\locked.txt' 17 18 def deny_account(username): 19 print('您的用户已被锁定!') 20 with open(locked_file, 'a') as deny_f: 21 deny_f.write('\n' + username) 22 23 def main(): 24 retry_count = 0 25 retry_limit = 3 26 while retry_count < retry_limit: 27 username = input('\033[32;1m请输入用户名:\033[0m') 28 if len(username) == 0: 29 print('用户名不能为空,请重新输入!') 30 continue 31 with open(locked_file, 'r') as lock_f: 32 for line in lock_f.readlines(): 33 if username == line.strip(): 34 sys.exit('\033[32;1m用户 %s 已经被锁定!\033[0m' % username) 35 36 37 while True: 38 password = input('\033[32;1m请输入密码:\033[0m') 39 if len(password) == 0: 40 print('密码不能为空,请重新输入!') 41 continue 42 else: 43 break 44 with open(account_file, 'r') as account_f: 45 flag = False 46 for line in account_f.readlines(): 47 if len(line.strip()) == 0: 48 continue 49 user, pawd = line.strip().split() 50 if username == user and password == pawd: 51 print('success!') 52 flag = True 53 break 54 if flag == False: 55 if retry_count < 2: 56 print('您的用户名或密码有误,请重新输入!') 57 retry_count += 1 58 else: 59 print('欢迎用户%s登陆老男孩系统!' % username) 60 break 61 else: 62 deny_account(username) 63 64 if __name__ == '__main__': 65 main()
2020-6-29-Python3-day1作业
猜你喜欢
转载自www.cnblogs.com/laotieshan/p/13207648.html
今日推荐
周排行