- count_input = 0#错误计数,用于错误3次时提示lock_list = []#锁定列表,连续错误3次提示并加入到用户锁定文件
- foriinrange(3):
- count_input += 1
- input_account = input("Input your account : ")
- input_password = input("Input your password : ")
- lock_list.append(input_account) #将用户添加进锁定列表f1 = open("password_file","r")#读帐户密码文件f2 = open("lock_file","r")#读用户锁定文件
- forline2in f2:
- ifinput_account.strip() == line2.strip():#判断用户输出帐户与锁定文件行是否相等,相等即用户锁定状态,则提示退出,否则继续
- print("your account has been locked! quit...")
- f2.close()
- break
- else:
- forline1in f1:
- ifinput_account+" "+input_passwordinline1:#判断输出帐户密码与帐户密码文件是否相等,相等即打印欢迎信息并退出,否则继续
- print("welcome back!")
- f1.close()
- break
- else:
- ifcount_input < 3:#当错误计数器小于3时,则提示重新输入,继续下次循环
- print("wrong ! please input again!")
- continue
- else:
- iflock_list.count(input_account) == 3:#当错误计数器等于3时,提示用户被锁定,并退出
- print("wrong password!your account have been lock")
- f2 = open("lock_file","a")#以追加形式打开用户锁定文件f2.write(input_account+"\n")#将锁定用户添加入锁定文件
- f2.close()
- else:
- print("you have input wrong password 3 times,quit..")#三次输入帐号不全相同时,打印此行,并退出
- break
- break
来源: http://www.bubuko.com/infodetail-1960451.html