#! /usr/bin/env python # -*- coding: utf-8 -*- # __author__ = "Deakin" # Email: 469792427@qq.com # Date: 2018/1/8 #模拟登陆: #1. 用户输入帐号密码进行登陆 #2. 用户信息保存在文件内 #. 用户密码输入错误三次后锁定用户 f_lock=open("lock_list",'r+',encoding="utf-8") f_account=open("account",'r',encoding="utf-8") account = input("pls key in your account name:") while True: for lockline in f_lock: lockline=lockline.strip('\n') if account==lockline: print("your account has been locked, pls contact the system administrator") exit() else: pass for accountline in f_account: (user,passwd)=accountline.strip('\n').split() #分辨判断account password是否匹配 if account==user: count=0 while count<3: password=input("pls key in your password:") if password==passwd: print("welcome to login,%s"%(account)) exit() else: if count!=2: print("your password is not correct,pls try again,remain %s times"%(2-count)) elif count==2: #在第三次输错的时候不打印还剩几次机会 pass count+=1 else: f_lock.write(account+'\n') print("your account has been locked,pls contact your system administrator") exit() else: print("account don't existed") break