Python 模拟三次用户登录,登录失败锁定账号并写入文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 模拟三次用户登录,登录失败锁定账号并写入文件相关的知识,希望对你有一定的参考价值。
登录要求:
1、用户输入登录账号 、密码,登录成功显示欢迎用户登录界面
2、 用户可以尝试三次登录,三次登录失败后,将锁定用户,并输出到新的文件当中。
count = 0 while count < 3 : file1 = open("accounts.txt", "r") data1 = file1.read().strip().split() username = input("Please input your username>>>> ") password = input("Please input your password>>>> ") if username == data1[0] and password == data1[1]: print("welcom to %s login" %username) break; elif username == data1[2] and password == data1[3]: print("welcom to %s login" % username) break; elif username == data1[4] and password == data1[5]: print("welcom to %s login" % username) break; else: print("user %s login is failure please try again" % username) count = count + 1 else: file2 = open("lock_userlist.txt", "w") file2.write(username) print("you have try 3 times your %s is locked\n" %username)
accounts.txt
测试:登录成功
测试 :登录失败
以上是关于Python 模拟三次用户登录,登录失败锁定账号并写入文件的主要内容,如果未能解决你的问题,请参考以下文章