附有流程图能够看一看,第一次画会慢慢改进的。ide
代码以下:ip
1.User 用户名存储文件utf-8
王二 123 张三 1234 李四 123456
2.Lock_User 被锁用户文件input
3. Land.py 主程序文件it
#coding=utf-8class
import sysimport
i=0coding
while i<3:循环
print("----Welcome------")遍历
account = raw_input("Input your account:") /用户帐号输入
Lock_list = open('Lock_User','r+') /打开加锁文件,读写方式
Lock_user = Lock_list.readlines() /将获取的信息提取到list中
User_list = open('User')
User = User_list.readlines()
for Lock_line in Lock_user:
Lock_line = Lock_line.strip('\n') /去掉\n符,提取出可用信息
if account == Lock_line: /遍历核对帐号是否加锁
sys.exit('用户%s已经被锁定,系统退出!' % account)
for User_account in User:
(User,Password) = User_account.strip('\n').split()
if account == User: /帐号匹配循环
j = 0
while j < 3:
passwd = input("Input your passworld:")
if str(passwd) == Password:
print ("欢迎%s登录管理系统"% account)
sys.exit(0)
else:
if j!=2:
print("用户%s密码输入错误,您还有 %d 次机会"
%(account,2-j))
j = j+1
else:
Lock_list.write(account + '\n') /密码匹配失败,锁定帐号
sys.exit('用户%s已被锁定' % account)
else:
pass /帐号不存在先pass,超出三次退出系统
else:
if i!=2:
print("用户%s不存在!,请从新输入,还有%d次机会"
%(account,2-i))
i +=1
else:
sys.exit("用户%s不存在,退出!" % account )
Lock_list.close()
User_list.close()