
需求:
写一个用户登录窗口验证输入的用户名和密码,若正确打印欢迎信息,输入错误三次则加入锁定名单。锁定名单要持久化存储 1 # *-* Coding:utf-8 *-* 2 # Auth: wangxz 3 import pickle 4 5 print("-------the login---------") 6 _username = "wangxz" 7 _passwd = 123456 8 9 def username_is_lock(name):10 with open(".\login.text", "rb") as fobj:11 name_List = []12 try:13 name_List.append(pickle.load(fobj))14 except EOFError: # 这个异常没有任何影响15 return None16 try:17 name_List.index(name)18 except Exception as e:19 return False # 没有在被锁定的文件中找到用户20 else:21 return True # 在被锁定的文件中找到用户22 23 24 25 REsubmit_COUNT = 0 # 定义一个常量26 while True:27 if REsubmit_COUNT <= 3:28 username = input("username: ")29 if not username_is_lock(username): # 没有找到文件30 passwd = input("password: ")31 if _username == username and _passwd == passwd: # 登录成功32 print("The login successfully!")33 break34 else:35 REsubmit_COUNT += 136 if REsubmit_COUNT == 3: # 已经输入三次,账户锁定37 print("The Warning! Your account has been locked")38 with open(".\login.text", "wb") as fd: # 写入文档39 pickle.dump(username, fd)40 break41 else:42 print("Please input your account and passwd again!")43 else: # 若已经在锁定文档中找到文件,则打印信息直接退出44 print("Your account has benn locked.\r\nPlease connection the wxz ")45 break代码执行过程中有点问题:
在序列号存储时,不是追加写入,这次的写入会把上次的写入覆盖掉!有待研究!
总结以上是内存溢出为你收集整理的一个python代码练习全部内容,希望文章能够帮你解决一个python代码练习所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)