• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
程序员日志
博客园    首页    新随笔    联系   管理    订阅  订阅

模拟登陆作业

作业要求如下
'''
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

 

本章博客由作者刘少辉著写
posted @ 2018-09-28 10:14  程序小霸王  阅读(177)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3