students={"张三":{"name":"张三", "ID":202001, "语文":89, "数学":97, "英语":91 }, "李四":{"name":"李四", "ID":202002, "语文":97, "数学":81, "英语":90 }, "王五": {"name": "王五", "ID": 202003, "语文": 97, "数学": 100, "英语": 94 }, "赵六": {"name": "赵六", "ID": 202004, "语文": 81, "数学": 92, "英语": 73 } } def showinfo(): print("-"*110) print(''' 学生成绩系统 1.添加学生信息 2.删除学生信息 3.修改学生信息 4.查询学生信息 5.学生成绩排序 6.列出所有学生信息 7.退出程序''') print("-"*110) def paixu(a,b): return [name for name in students.keys()if students[name][a]>=b] c=0 while True: showinfo() choice=input("请输入你的选择:") if choice=="1": id=int(input("要添加的学生的ID:")) c=0 for i in students: if id==students[i]["ID"]: c=1 break if c==1: print("学生已在列表中") else: d1=input("学生姓名:") students[d1]={ "name": d1, "ID": id, "语文": int(input("语文成绩:")), "数学": int(input("数学成绩:")), "英语": int(input("英语成绩:")) } elif choice=="2": id = int(input("要删除的学生的ID:")) c = 0 for i in students: if id == students[i]["ID"]: c = 1 break if c == 1: print("学生没在列表中") else: d1 = input("学生姓名:") del students[d1] elif choice=="3": id = int(input("要修改的学生的ID:")) c = 0 d=0 for i in students: d=i if id == students[i]["ID"]: c = 1 break if c: del students[d] d1 = input("学生姓名:") students[d1] = { "name": d1, "ID": id, "语文": int(input("语文成绩:")), "数学": int(input("数学成绩:")), "英语": int(input("英语成绩:")) } else: print("不在列表") elif choice=="4": id = int(input("要查询的学生的ID:")) for i in students: if id == students[i]["ID"]: c = 1 break if c == 1: print("学生没在列表中") else: d1 = input("学生姓名:") print(d1,students[d1]) elif choice=="5": a=input("学科:") b=int(input("筛选成绩:")) print(paixu(a,b)) elif choice=="6": for i in students: print(i,students[i]) elif choice=="7": print("退出程序") break else: print("无效输入,请重新输入")