python简单的命令行学生成绩管理系统

#一个简单的学生管理系统
students_dict = {
    "1001": {
        "name": "yuan",
        "scores": {
            "chinese": 100,
            "math": 89,
            "english": 100,
        }
    },
    "1002": {
        "name": "rain",
        "scores": {
            "chinese": 100,
            "math": 100,
            "english": 100,
        }
    },
}

"""
查看所有学生成绩

"""
def get_stu_score():
    print("*"*60)
    for stu_id,stu_dict in students_dict.items():
        name=stu_dict.get("name")
        chinese=stu_dict.get("scores").get("chinese")
        math=stu_dict.get("scores").get("math")
        english=stu_dict.get("scores").get("english")
        print("学号:%4s 姓名:%4s 语文成绩:%4d 数学成绩:%4d 英语成绩:%4d" % (stu_id,name,chinese,math,english))
    print("*"*60)  

"""
添加一个学生的成绩

"""
def add_stu_score():
    while 1:
        stu_id=input("请输入学生学号>>>")
        if stu_id in students_dict.keys():
            print("该学号已存在!!!")
            continue
        break
        

    #请输入姓名
    name=input("请输入学生姓名>>>")

    #请输入语文成绩
    while 1:
        chinese=input("请输入语文成绩>>>")
        try:
            chinese=int(chinese)
            if chinese<0 or chinese>100:
                print("分数不符合要求,请输入1~100")
                continue
        except Exception as e:
            print("输入的类型不符合")
            continue
        break
        
    #请输入数学成绩
    while 1:
        math=input("请输入数学成绩>>>")
        try:
            math=int(math)
            if math<0 or math>100:
                print("分数不符合要求,请输入1~100")
                continue
        except Exception as e:
            print("输入的类型不符合")
            continue
        break
    #请输入英语成绩
    while 1:
        english=input("请输入英语成绩>>>")
        try:
            english=int(english)
            if english<0 or english>100:
                print("分数不符合要求,请输入1~100")
                continue
        except Exception as e:
            print("输入的类型不符合")
            continue
        break 
    #构建数据类型
    stu_score={
        "chinese":chinese,
        "math":math,
        "english":english
    }
    stu_dic={
        "name":name,
        "scores":stu_score
    }
    students_dict[stu_id]=stu_dic
    print("*"*60)
    print("学生成绩添加成功")
    print("学号:%4s 姓名:%4s 语文成绩:%4d 数学成绩:%4d 英语成绩:%4d" % (stu_id,name,chinese,math,english))
    print("*"*60)

"""
修改一个学生的成绩

"""
def upd_stu_score():
    while 1:
        stu_id=input("请输入要修改成绩的学号>>>")
        if stu_id not in students_dict:
            print("输入的学号不存在,请重新输入")
            continue
        else:
            break
           
    #语文成绩检测
    while 1:
        chinese=input("请输入语文成绩>>>")
        try:
            chinese=int(chinese)
            if chinese<0 or chinese>100:
                print("分数不符合要求,请输入1~100")
                continue
            else:
                break
        except Exception as e:
            print("输入的类型不符合")
            continue
               
    #数学成绩检测
    while 1:
        math=input("请输入数学成绩>>>")
        try:
            math=int(math)
            if math<0 or math>100:
                print("分数不符合要求,请输入1~100")
                continue
            else:
                break
        except Exception as e:
            print("输入的类型不符合")
            continue
            
    #英语成绩检测
    while 1:
        english=input("请输入英语成绩>>>")
        try:
            english=int(english)
            if english<0 or english>100:
                print("分数不符合要求,请输入1~100")
                continue
            else:
                break
        except Exception as e:
            print("输入的类型不符合")
            continue
    #构建数据
    stu_scores={
        "chinese":chinese,
        "math":math,
        "english":english
    }
    stu_dict={
        "scores":stu_scores
    }
    stu_dicts={
        stu_id:stu_dict       
    }
                
    #修改数据
    students_dict.update(stu_dicts)
    print("修改成功")


"""
删除一个学生的成绩

"""
def del_stu_score():
    while 1:
        sid=input("请输入要删除学生的学号>>>")
        if sid in students_dict.keys():
            students_dict.pop(sid)
            print("删除学生成绩成功!")
            break
        else:
            print("没有该学生!!!")
            continue
        



while 1:
    print("""    
       1.  查看所有学生成绩
       2.  添加一个学生成绩
       3.  修改一个学生成绩
       4.  删除一个学生成绩
       5.  退出程序
    """)
    choice=input("请输入您的选择:")
    #查看学生信息
    if choice=="1":
        get_stu_score()
        continue
    
    #添加学生信息
    elif choice=="2":
        #请输入学号
        add_stu_score()
        continue
    
    #修改学生成绩  
    elif choice=="3":
        upd_stu_score()
        continue

    #删除学生信息
    elif choice=="4":
        #请输入学号
        del_stu_score()
        continue
        
        

    #退出程序        
    elif choice=="5":
        break
    else:
        print("您的输入有误!")
        continue

这个学生成绩管理系统并未涉及数据库存储,只为初学者提供参考。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值