需求:
编写登录接口:
1.输入用户名和密码登录
2.输错三次锁定账户
3.下次登录还是上次的账户,提示锁定,直接退出
4.成功 后显示登录成功
锁定判断文件:
lock.txt 内容:
xiaoc
xiaoe
登录判断文件:
ccount.txt 内容:
xiaoa 123
xiaob 123
xiaoc 123
xiaod 123
xiaoe 123
流程图:
搬运实现代码:
#!/usr/bin/python3
# czh
#lock定义为锁定文件
lock = "D:\Projectpython3\day1\lock.txt"
#account定义为账户文件
account = "D:\Projectpython3\day1\ccount.txt"
#计数器
count = 0
#标识器
flag = False
#定义锁定用户列表为空
lock_user = []
#account_user = []
#打开锁定文件,并读取锁定账户
f1 = open(lock,'r')
lock_file = f1.readlines()
f1.close()
#循环锁定账户,将账户追加到lock_user列表中
for i in lock_file:
i = i.strip('\n')
lock_user.append(i)
f2 = open(account,'r')
account_file = f2.readlines()
f2.close()
while True:
name = input("input you name:")
password = input("input you password:")
if name in lock_user:
print("user in lock")
else:
count +=1
if count > 2:
print("错误三次 用户已经锁定")
with open(lock,'a') as f:
f.write("\n" + name)
break
else:
for i in account_file:
n1,p1 = i.strip().split()
if n1 == name and p1 == password:
print("welcome.....")
flag = True
#break
else:
continue
if flag is True:
break