day12-作业

import json


def choices():
    print('==================================')
    print('欢迎来到**学生管理系统')
    print()
    print('♦1.注  册')
    print()
    print('♦2.登  录')
    print()
    print('♦3.退  出')
    print('==================================')


def func():
    while True:
        choices()
        num = int(input('请选择需要的功能:'))
        if num == 1:
            with open('./files/info', 'r', encoding='utf-8') as f:
                info = json.loads(f.read())
            while True:
                user = input('请输入账号(2-10位):')
                if len(user) < 2 or len(user) > 10:
                    print('账号不符合要求!')
                    break
                user_sign_list = []
                for key in info:
                    user_sign_list.append(key)
                if user in user_sign_list:
                    print('账号已存在,请选择可注册账号!')
                    continue
                pwd = input('请输入密码(6-18位):')
                if len(pwd) < 6 or len(pwd) > 18:
                    print('密码不符合要求!')
                    break
                info[user] = pwd
                print('您已成功注册!')
                choose = input('是否继续:(y/n):')
                if choose == 'n':
                    break
            with open('./files/info', 'w', encoding='utf-8') as f:
                f.write(json.dumps(info))
        elif num == 2:
            with open('./files/info', 'r', encoding='utf-8') as f:
                info = json.loads(f.read())
            user = input('请输入账号:')
            pwd = input('请输入密码:')
            user_list = []
            for key in info:
                user_list.append(key)
            if user in user_list:
                for key in info:
                    while key == user and info[key] == pwd:
                        print('登录成功!')
                        person_info()
                        break
                    while key == user and info[key] != pwd:
                        print('登陆失败,输入密码有误!')
                        break
            else:
                print('用户未注册!')
        elif num == 3:
            print('您已成功退出!')
            break


def person_info():
    print('==================================')
    print('♦1.查 看 课 程')
    print('♦2.查 看 成 绩')
    print('♦3.添 加 好 友')
    print('♦4.返 回')
    print('==================================')
    while True:
        num = int(input('请选择需要的功能:'))
        if num == 4:
            return 0
# 未完待续...

if __name__ == '__main__':
    func()


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