模拟登陆作业

作业要求如下
'''
1. 用户输入帐号密码进行登陆
2. 用户信息保存在文件内
3. 用户密码输入错误三次后锁定用户
'''
 1 f=open('user_list','r')
 2 
 3 dic={}
 4 lock_list=[]
 5 with open('lock_file','r+') as f_file:
 6     for line in f:
 7         line = line.strip().split()
 8 
 9         dic[line[0]] = line[1]
10     print(dic)
11 
12 count = 0
13 while True:
14     username=input('请输入用户名》:')
15     passwd=input('请输入密码》:')
16     if username in dic:
17         print('you')
18         if username in lock_list:
19             print('您的用户%s已经被锁定' %username)
20 
21         else:
22             if passwd==dic[username]:
23                 print('登陆成功')
24 
25             else:
26                 count+=1
27                 if count==3:
28                     print('您的%s密码输入错误三次,已经被锁定' %username)
29                     lock_list.append(username)
30                     print(lock_list)
31                     with open('lock_file','a')as f_lock:
32                         f_lock.writelines(str(lock_list)+'\n')
33                 else:
34                     print('密码有误,请重新输入')
35     else:
36         print('无效用户')
37 f.close()
View Code

 

转载于:https://www.cnblogs.com/liushaohui/p/9717117.html

你可能感兴趣的:(模拟登陆作业)