#在同一目錄創建login.txt文件哦 #打開txt讀取文件 \file = open('login.txt','r+') user = [['zhangsan','1234'],['lisi','1234'],['alex','1234']]data = []for i in file: dat ...
#在同一目錄創建login.txt文件哦
#打開txt讀取文件
\file = open('login.txt','r+')
user = [['zhangsan','1234'],['lisi','1234'],['alex','1234']]
data = []
for i in file:
data = (i.strip('\n').split(','))
count = 0
while count < 3:
username = input("用戶名:").strip()
if username in data:
print("用戶已被鎖定!")
break
password = input("密碼:").strip()
for k in user:
if username == k[0] and password == k[1]:
print("welcome %s" % (k[0]))
exit()
#成功登陸後不需要再輸入用戶名 直接退出
else:
print("密碼輸入錯誤!\n")
count += 1
if count == 3:
print("密碼輸入上限,用戶已鎖定!")
data.append(username)
for k in data:
file.write(k)
file.write(",")
file.close()