day12 - 基础学生管理系统

def loginview():
    print("          1.登陆             ")
    print("          2.注册             ")
    print("          3.退出             ")

    print("=============================")


with open("files/student.txt", 'r', encoding="utf-8") as f:
    users = eval(f.read())

while True:
    loginview()
    option = input("请输入您的操作(1-3)")
    if option == '1':
        while True:
            name = input("请输入用户名(3-6)位")
            if name not in users:
                print("该用户不存在,请注册")
                break
            secret = input("请输入密码(3-6)位")
            if users[name] != secret:
                print("密码输入错误")
                break
            else:
                print("登陆成功")
                break
    elif option == '2':
        while True:
            number = input("请输入账号(3-6)位")
            if number in users:
                print("你输入的账号已经存在,请重新输入")
                break
            elif len(number) > 6 or len(number) < 3:
                print("账号必须是3-6位,请重新输入")
                break
            secret = input("请输入密码")
            users[number] = secret
            values = input("是否继续(y/n):")
            if values == 'n':
                print("注册成功")
                break
        with open("files/student.txt", 'w', encoding="utf-8") as f:
            f.write(str(users))
    elif option == '3':
        break

你可能感兴趣的:(day12 - 基础学生管理系统)