# edit by weiwei xu
# -*- coding:UTF-8 -*-
f=open(‘user‘,‘r‘,encoding=‘utf-8‘)
fstr=f.readlines()#读文件,读出来是列表
fuser=fstr[0:-1:2]#从开始没隔一个取一个值,这个是account
fpword=fstr[1::2]#这个是password,中间不写0.才能取到最后一个值
i = 1
while i <= 3:
account=str(input("please input your account:"))
password=str(input("please input your password:"))
for n in fuser:
fuser_account=n.strip()#取account付给变量,方便进行字符串对比
if account == fuser_account:
for m in fpword:
fuser_pword=m.strip()#取密码值付给变量以便后面进行对比
if password==fuser_pword:
print("welcome to my school")
exit()
f = open(‘incorrect-user‘, ‘r‘, encoding=‘utf-8‘)#读取incorrect-user账户里账号,准备做对比
for line in f:
fuser_lock=(line.strip())
if account==fuser_lock:#判断account是否已被锁定
print("your account has been locked")
exit()
i=i+1
print("your account is incorrect ,please re-enter:")
f=open(‘incorrect-user‘,‘a+‘,encoding=‘utf-8‘)
f.write(account+"\n")
print("your account has been locked")