Python学生管理系统

代码

# 定义学生容器
all_dict = {"001": {"no": "001", "name": "张三", "age": 22, "score": 99}}


# 界面
def jm():
    print("===================")
    print("===学生管理系统===")
    print("1:添加学生")
    print("2:删除学生")
    print("3:修改学生")
    print("4:查询学生")
    print("5:查看所有学生信息")
    print("6:退出程序")
    print("7:统计平均分")
    print("8:统计及格率")
    print("0:回到主菜单")
    print("===================")


# 添加
def add_stud():
    while True:
        stud_no = input("请输入要添加学生的学号")
        if stud_no in all_dict:
            print("该学号已经使用")
        else:
            stud_name = input("请输入新学生的名字")
            stud_age = input("请输入新学生的年龄")
            stud_sco = input("请输入新学生的分数")
            stu_dict = {"no": stud_no, "name": stud_name, "age": stud_age, "score": stud_sco}
            all_dict[stud_no] = stu_dict
            print("==添加新学生成功==")
            return


# 删除
def del_stud():
    while True:
        stud_no = input("请输入要删除学生的学号")
        if stud_no  not in all_dict:
            print("==该学生不存在==")
        else:
            del all_dict[stud_no]
            print("==删除成功==")
            return


# 修改
def xg_stud():
    while True:
        stud_no = input("请输入要修改学生的学号")
        if stud_no not in all_dict:
            print("==该学生不存在==")
        else:
            new_name = input("请输入新的学生名字")
            new_age = input("请输入新的学生年龄")
            new_score = input("请输入新的学生分数")
            new_dict = {"name": new_name, "age": new_age, "score": new_score}
            all_dict[stud_no] = new_dict
            print("==修改学生信息成功==")
            return


# 查询
def cx_stud():
    while True:
        stud_no = input("请输入要查询学生的学号")
        if stud_no not in all_dict:
            print("==该学生不存在==")
        else:
            print("==查询结果==")
            all_dict[stud_no]
            return


# 查询所有
def all_stud():
    print("==所有学生信息如下==")
    for all in all_dict.values():
        print("学号:%s|姓名:%s|年龄:%d|成绩:%d" % (all["no"], all["name"], all["age"], all["score"]))
    print("====================")


# 求平均数
def pjs_sco():
    l = len(all_dict)
    sum = 0
    for pj in all_dict.values():
        fs = int(pj["score"])
        sum += fs
    pjs = sum / l
    print("平均数为%d" % pjs)


# 及格率
def jgl_sco():
    l = len(all_dict)
    num = 0
    for jg in all_dict.values():
        fss = int(jg["score"])
        if fss > 59 and fss < 101:
            num += 1
    jgl = num / l * 100
    print("及格率为%d%%" % jgl)


# 主函数方法
def xz_dict():
    while True:
        jm()
        pd = int(input("请选择相对应的序号实现功能"))
        if pd == 1:
            add_stud()
            print(all_dict)
        elif pd == 2:
            del_stud()
            print(all_dict)
        elif pd == 3:
            xg_stud()
            print(all_dict)
        elif pd == 4:
            cx_stud()
            print(all_dict)
        elif pd == 5:
            all_stud()
        elif pd == 6:
            print("==程序结束==")
            return
        elif pd == 7:
            pjs_sco()
        elif pd == 8:
            jgl_sco()
        elif pd == 0:
            jm()

xz_dict()

效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值