您的位置:首页 > 编程语言 > Python开发

python 登陆接口 作业1

2017-12-15 22:11 344 查看
from collections import Counter
'''
登陆接口
'''
clean = input("clean Y or N:")
if (clean == "Y" or clean=="y"):
with open("lock.txt","w") as f:
f.close()
login_info='''欢迎登陆!'''
f_read=open("user.txt","r")
f_read_lock=open("lock.txt","r")
user={}
lock=[]
for line in f_read:
username, password= line.strip().split(",")
user[username]=password
print(user)#直接查看字典
for line in f_read_lock:
lock.append(line.strip())
print(lock)
#遍历字典
# for key in dict:
#     print(dict[key])
# for line in open("lock.txt","r"):
#     username, password= line.strip().split(",")
#     user[username]=password
n=0
while(n<3):
with open("lock.txt", "a") as f:
input_name = input("name:")
input_password = input("password:")
f.write(input_name+"\n")
f.close()
count_user=Counter(lock)
if input_name in count_user.keys() and count_user.get(input_name)>=3:
print("账户锁定")
break
elif input_name in user and input_password == user[input_name]:#in 代替了 2.x has_key
print(login_info)
break
else:
print("账户名或密码错误"+"\n")
n=n+1

if(n==3):
print("输入大于三次,退出")


user.txt放入自己指定的用户名密码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python