Day12 - 作业

学生管理系统

import time
#注册界面
def register():
    with open('files/users', 'r', encoding='utf-8') as f:
        users = eval(f.read())
        # user_name = input('请输入3-6位用户名:')

        while True:
            user_name = input('请输入3-6位用户名:')
            if user_name not in users:
                while True:
                    if not 2 < len(user_name) < 7:
                        user_name = input('请输入3-6位正确用户名:')
                    else:
                        break
                pw = input('请输入6-10位用户密码:')
                while True:
                    if 6 <= len(pw) <= 10:
                        break
                    else:
                       pw = input('请输入6-10位正确用户密码:')
                users[user_name] = pw
                value = input('是否继续(y/n):')
                if value == 'n':
                    break
            else:
                print('该用户已注册')
                print('按1返回')
                x = int(input(''))
                if x == 1:
                    break
    # print(users)
    with open('files/users', 'w', encoding='utf-8') as f:
        f.write(str(users))
    students()

# 登陆成功模块
def success():
    with open('files/users', 'r', encoding='utf-8') as f:
        users = eval(f.read())
        # name = users[user_old]
    print('====================================')
    print('❀❀欢迎                          ')
    print('       ❤   1.   添加学生           ')
    print('       ❤   2.   查看学生           ')
    print('       ❤   3.   修改学生信息       ')
    print('       ❤   4.   删除学生           ')
    print('       ❤   5.   返回               ')
    print('====================================')
    choices = int(input('请选择(1-5):'))
    if choices == 1:
        register()
    if choices == 2:
        with open('files/users', 'r', encoding='utf-8') as f:
            users1 = eval(f.read())
            print(users1)
            # if input(''):
            print('按1返回')
            x = int(input(''))
            if x == 1:
                success()

    if choices == 5:
        students()


# 登录模块
def login():
    with open('files/users', 'r', encoding='utf-8') as f:
        users = eval(f.read())
        # print(users)
        # global user_old
        user_old = input('请输入3-6位用户名:')
        if user_old in users:
            for key in users:
                # user_old = input('请输入3-6位用户名:')
                password_old = input('请输入6-10位用户密码:')
                while True:
                    if password_old == users[user_old]:
                        success()
                        break
                    else:
                        password_old = input('请输入6-10位用户密码:')
        else:
            print('该用户不存在')
            print('按1返回')
            x = int(input(''))
            if x == 1:
                students()

def students():
    print('============================================')
    print('                                            ')
    print('         欢迎来到xx学院学生管理系统         ')
    print('                                            ')
    print('          ❤   1. 登       录               ')
    print('          ❤   2. 注       册               ')
    print('          ❤   3. 退       出               ')
    print('                                            ')
    print('============================================')
    num = int(input('请选择服务(1-3):'))
    if num == 1:
        login()
    if num == 2:
        register()
    if num == 3:
        pass

students()

你可能感兴趣的:(Day12 - 作业)