1

import os
tag = 1
while tag:
    inp_user = input("请输入账号").strip()
    with open("user_info3.txt", mode="r", encoding="utf-8") as f1, \
            open("user_info3_copy.txt", mode="w", encoding="utf-8") as f2:
        for line in f1:
            user, password, count = line.strip().split(":")
            count = int(count)
            if inp_user == user:
                if count == 3:
                    print("账号被锁定")
                else:
                    for i in range(3):
                        inp_psw = input("请输入密码").strip()
                        if inp_psw == password:
                            print("登陆成功")
                            tag = 0
                            break
                        count += 1
                        if count == 3:
                            print("密码错误三次,账号锁定")
                            break
                    else:
                        print("密码错误三次,账号锁定")
                        count = "3"
                    count = str(count)
            f2.write("{}:{}:{}\n".format(user, password, count))

    os.remove('user_info3.txt')
    os.rename("user_info3_copy.txt","user_info3.txt")

1

 posted on 2020-03-16 23:24  wwwpy  阅读(140)  评论(0编辑  收藏  举报