file_object = open('userdata.txt') userdatadic = { } log=0 erroruesr={} def login(): for line in file_object: line = line.strip('\n') userdatalist =line.split('---') userdatadic[userdatalist[0]] = userdatalist[1] #从数据库中调用信息 for i in range(3): username=input("uesrname:") FBItext = open('FBI.txt') for line in FBItext: line = line.strip('\n') if line ==username: print("you're lose too many mistakes") return #判断是否黑名单 else: password=input("password:") for value in userdatadic.keys(): if value==username: if userdatadic[value]==password: print("welcome") log = 1 break #对比账号密码 else: for v in erroruesr.keys(): if v == username: erroruesr[username] += 1 break else: erroruesr[username] = 1 #记录输出的信息 if log == 1: break else: for v in erroruesr.values(): if v>=3: f = open("FBI.txt", 'a') f.write(username+"\n") f.close() print("you're lose too many mistakes") #对比输错信息,并保存 login()