作业涉及知识点:循环控制,文件读写访问,以及列表相关操作。
count = 0
flag = 1
waitstaus = 0
list=[]
while True:
flag = 1
#输入用户名(user)判断是否被锁定
user = input("Please Input User:")
for i in range(len(list)):
if user == list[i]:
print("此用户被锁定,请输入其他用户")
flag = 0
break
if (flag == 1 ):
while True:
count += 1
if count <= 3:
key = input("Please Input Key:")
if user == 'admin'and key == 'python':
print("欢迎,登录成功^_^")
while True:
waitstaus += 1
#一个用户输入密码超过三次被锁定
else:
f = open("D:\\Python\\project\\userblocked.txt",'w')
f.write(user)
f.close()
# 打开磁盘文件,读取已经被锁定的用户存储到列表中
f = open("D:\\Python\\project\\userblocked.txt", 'r')
str = f.read()
f.close()
list.append(str)
count = 0
break