day12-作业

"""author = Zard"""

学生管理系统

import json
with open('files/stu_info.json', 'r', encoding='utf-8') as f:
    content = f.read()
    stu_add = json.loads(content)

gen1 = (x for x in range(1,10000))
# 试图写返回函数,失败。
# def wyk_back():
#     print('‖=================华丽的分割线=================‖')
#     print('1.继续')
#     print('2.返回')
#     x = input('请选择:')
#     if int(x) == 2:
#         m = 0

# 增加学生
def wyk_insert():

    m = 1
    while m:
        # 此处有难点,添加的学生学号保存不了---使用生成器解决
        stu_info = {}
        print('‖=================添加学生==================‖')
        stu_info["姓名"] = input('输入学生姓名:')
        stu_info["年龄"] = input('输入学生年龄:')
        stu_info["电话"] = input('输入学生电话:')
        stu_info["学号"] = str(next(gen1)).zfill(4)
        stu_add.append(stu_info)
        for i in stu_add:
            print(i)

        print('‖==================添加成功==================‖')
        print('1.继续')
        print('2.返回')
        x = input('请选择:')
        if int(x) == 2:
            m = 0



# 删除学生
def wyk_delete():
    del_stu = input('‖============请输入删除学生的姓名或学号:')
    for u in stu_add:
        if del_stu == u['姓名'] or del_stu == u['学号']:
            stu_add.remove(u)
            for i in stu_add:
                print(i)
            break


# 查看学生
def wyk_look():
    m = 1
    while m:
        for i in stu_add:
            print(i)
        print('‖=================华丽的分割线=================‖')
        print('1.继续')
        print('2.返回')
        x = input('请选择:')
        if int(x) == 2:
            m -= 1


# 修改学生
def wyk_recom():
    m = 1
    while m:
        recom_stu = input('‖============请输入需要修改的学生姓名或学号:')
        for y in stu_add:
            if recom_stu == y['姓名'] or recom_stu == y['学号']:
                print('‖=================修改学生==================‖')
                y['姓名'] = input('输入学生姓名:')
                y['年龄'] = input('输入学生年龄:')
                y['电话'] = input('输入学生电话:')
                for i in stu_add:
                    print(i)
                print('‖=================华丽的分割线=================‖')
                print('1.继续')
                print('2.返回')
                x = input('请选择:')
                if int(x) == 2:
                    m -= 1

# 操作页面
def stu_op(x):
    m = 1
    while m:
        print('‖================================================‖')
        print('‖☺☺☺☺欢迎来到蓝翔技术学院学生管理中心☺☺☺☺‖')
        print('‖欢迎技师: %s !                                ‖' % x)
        print('‖                                                ‖')
        print('‖              ★ 1.添加                         ‖')
        print('‖              ★ 2.查看                         ‖')
        print('‖              ★ 3.修改                         ‖')
        print('‖              ★ 4.删除                         ‖')
        print('‖              ★ 5.返回                         ‖')
        print('‖================================================‖')
        add_wyk = input('请输入您的选择(1-5):')
        if int(add_wyk) == 1:
            wyk_insert()
        if int(add_wyk) == 2:
            wyk_look()
        if int(add_wyk) == 3:
            wyk_recom()
        if int(add_wyk) == 4:
            wyk_delete()
        if int(add_wyk) == 5:
            break

f1 = open('./files/id_bank','r',encoding='utf-8')
id_bank = eval(f1.read())
f1.close()

# 登录
def login():
    while True:
        stu_id = input('‖============登陆中=========请输入★账号★:')
        stu_pw = input('‖===========登陆中=========请输入★密码★:')
        if stu_id in id_bank and str(id_bank[stu_id]) == stu_pw:
            print('‖===================登录成功==================‖')
            stu_op(stu_id)

            break
        else:
            print('‖===登录失败,账户或者密码有误!请重新输入===‖')
            break
# 注册
def register():
    while True:
        re_id = input('‖==========请输入您的注册账号========(字母或数字):')
        if  not ( 2 <= len(re_id) <= 20 and( 'a' < re_id < 'z' or 'A' <
            re_id < 'Z' or '0' < re_id < '9' or '\u4e00' < re_id < '\u9fa5')):
            print('‖=======输入有误,请重新输入具体账号信息!=======‖')
            continue
        if re_id in id_bank:
            print('‖===========账号已存在,请重新输入!=============‖')
            continue
        if 1 <= len(re_id) <= 10:
            re_pw = input('‖=========请输入您的注册密码========(字母或数字):')
            for x in re_pw:
                if  not ( 6 <= len(re_pw) <= 12 and( 'a' < re_pw < 'z' or
                        'A' < re_pw < 'Z' or '0' < re_pw < '9')):
                    print('‖==密码设置有误,请重新输入(不能带汉字,6-12位)==‖')
                    break
            else:
                print('‖==============注册成功,请重新登录=============‖')
                id_bank[re_id] = re_pw
                with open('./files/id_bank','w',encoding='utf-8') as f:
                    f.write(str(id_bank))
                login()
        else:
            print('‖=========账号输入有误请重新输入(1-10位)=========‖')

# 开始页面
def begin():
    count_out = 5
    while count_out:
        print('‖================================================‖')
        print('‖☺☺☺☺欢迎来到蓝翔技术学院学生管理中心☺☺☺☺‖')
        print('‖````````````````````````````````````````````````‖')
        print('‖                                                ‖')
        print('‖                                                ‖')
        print('‖              ★ 1.登录 ★                      ‖')
        print('‖            ★★ 2.注册 ★★                    ‖')
        print('‖          ★★★3.打扰了★★★                  ‖')
        print('‖                                                ‖')
        print('‖================================================‖')
        with open('./files/stu_info.json', 'w', encoding='utf-8') as f:
            content1 = json.dumps(stu_add)
            f.write(content1)
        choice = input('请输入您的选择(1-3):')
        if int(choice) == 1:
            login()
        if int(choice) == 2:
            register()
        if int(choice) == 3:
            count_out -= 1
            if count_out == 0:
                print('‖==============**!***!*****!!sb吧!=============‖')
                break
            print('‖========请继续!再接再厉,您还有%s次机会=========‖' % (count_out))
            continue
        else:
            print('‖===============输入有误,请重新尝试==============‖')
            continue

begin()

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