17..userinfo.txt 文件中存放以下结构:

alex:alex3714

wusir:123456

meet:meet123

1.让用户选择:

1.注册
2.登录

2.用户选择注册就将账号和密码添加到userinfo.txt中,如果用户名存在就提示用户名存在,不存在就进行添加(3分)

3.用户选择登录,就验证用户的账号和密码是否与userinfo.txt一致,如果一致终止循环提示登录成功(3分)

4.让用户登录三次,三次错误提示用户名已锁定,并打印错误次数(使用字符串格式化)(4分)
s = """
1.注册
2.登录

"""
count = 1
new_li = []
dic = {}
while 1:
num = input(s)
if num == "注册" or num == "1":
user = input("user:")
f = open("a1.txt",mode="r+",encoding="utf-8")
for i in f:
new_li.append(i.split("😊[0])
if user in new_li:
print("用户名存在!")
f.close()
else:
password = input("password:")
f.write("\n" + user + ":" + password)
print(count)
print("注册成功!")
f.close()
break
elif count < 4:
if num == "登录" or num == "2":
with open("a1.txt",mode="r",encoding="utf-8")as f1:
for i in f1:
user_list = i.split("😊
dic[user_list[0]] = user_list[1]

            user = input("user:")
            password = input("password:")
            if dic.get(user) == password:
                print("登陆成功!")
                break
            else:
                print("用户名或密码错误!")
                count += 1
    else:
        print("输入错误,请重新输入!")
        count += 1
else:
    print("用户名已被锁定,错误3次")
    break
posted @ 2019-06-18 20:52  God_with_us  阅读(422)  评论(0编辑  收藏  举报