代码
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()
效果