student = []
def print_menu():
print("学生管理系统V2.0")
print("=" * 30)
print("1.添加学生基本信息")
print("2.通过学号删除学生信息")
print("3.显示全部学生信息")
print("4.通过姓名查找学生的信息")
print("5.通过学号修改学生信息")
print("6.导出学生基本信息到指定路径的文件中")
print("7.查询成绩最高的学生基本信息")
print("8.查询成绩最低的学生基本信息")
print("9.根据学生综合成绩排序后显示基本信息")
print("10.根据输入的综合成绩,统计大于输入成绩的人数")
print("11.计算当前所有学生综合成绩的平均值")
print("12.退出系统")
print("=" * 30)
def add():
xh = input("请输入学生的学号:")
xm = input("请输入学生姓名:")
xb = input("请输入学生性别:(男/女)")
phone = input("请输入学生的手机号码:")
score = input("请输入学生的综合成绩:")
student_infos = {}
student_infos["xuehao"] = xh
student_infos["name"] = xm
student_infos["sex"] = xb
student_infos["phone"] = phone
student_infos["score"] = score
student.append(student_infos)
print(student)
def del_info():
stdId =input("请输入需要删除学生的学号:")
z = 0
for temp in student:
if stdId == temp['xuehao']:
indexxuehao = student.index(temp)
z = 1
break
else:
continue
if z ==1:
fina = input ("确认是否删除?(yes or no):")
if fina == "yes":
del student[indexxuehao]
print("恭喜您已成功删除该新学生了!")
else:
print("您放弃删除该学生信息了!")
else:
print("很抱歉,系统不存在该学生信息!")
def display():
print("*" * 30)
print("学生的信息如下:")
print("*" * 30)
print("序号 学号 姓名 性别 手机号码 综合成绩")
i = 1
for temp in student:
print("%d %s %s %s %s %s" % (
i, temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
i += 1
def find():
while True:
name = input("请输入要查找的学生姓名")
for temp in student:
if temp['name'] == name:
print("找到此学生,信息如下:")
print("学号:%s 姓名:%s 性别:%s 手机号码:%s 综合成绩:%s " % (
temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
break
else:
print("没有这个学生")
def change():
print("您选择了修改学生信息功能")
gai = input("请输入你要修改学生的学号:")
i = 0
ii = 0
for temp in student:
if temp["xuehao"] == gai:
ii = 1
break
else:
i = i + 1
if ii == 1:
while True:
xiaocaidan = int(input(" 1.修改学号\n 2.修改姓名 \n 3.修改性别 \n 4.修改手机号码 \n 5.修改综合成绩 \n 6.退出修改 \n"))
if xiaocaidan == 1:
aaa = input("输入更改后的学号:")
# 修改后的学号要验证是否唯一
i = 0
ii1 = 0
for temp1 in student:
if temp1["xuehao"] == aaa:
ii1 = 1
break
else:
i = i + 1
if ii1 == 1:
print("输入学号不可重复,修改失败!")
else:
temp["xuehao"] = aaa
print("学号已修改")
elif xiaocaidan == 2:
bbb = input("输入新的姓名:")
temp["name"] = bbb
print("姓名已修改")
elif xiaocaidan == 3:
ccc = input("输入新的性别(男/女):")
temp["sex"] = ccc
print("性别已修改")
elif xiaocaidan == 4:
ddd = input("输入新的手机号码:")
temp["phone"] = ddd
print("手机号码已修改")
elif xiaocaidan == 5:
eee = input("输入新的成绩:")
temp["score"] = eee
print("综合成绩已修改")
elif xiaocaidan == 6:
break
else:
print("输入错误请重新输入")
else:
print("学号输入错误,修改失败!")
def baocun():
file = open("xueshengxinxi.txt", "w")
file.write(str(student))
file.write('\n')
file.close()
def findmax():
studentone = []
for temp in student: # 遍历字典的成绩
studentone.append(temp["score"]) # 将遍历的成绩加入空列表
studentone.sort(reverse=True) # 将列表的值从大到小排序
n = studentone[0]
i = 0
j = 0
for temp in student:
if temp["score"] == n:
j = 1
break
else:
i = i + 1
if j == 0:
print("没有此学生,查询失败!")
else:
print("找到此学生,信息如下:")
print("学号:%s 姓名:%s 性别:%s 手机号码:%s 综合成绩:%s" % (
temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
def findmin():
studenttwo = []
for temp in student: # 遍历字典的成绩
studenttwo.append(temp["score"]) # 将遍历的成绩加入空列表
studenttwo.sort() # 将列表的值从小到大排序
n = studenttwo[0]
i = 0
j = 0
for temp in student:
if temp["score"] == n:
j = 1
break
else:
i = i + 1
if j == 0:
print("没有此学生,查询失败!")
else:
print("找到此学生,信息如下:")
print("学号:%s 姓名:%s 性别:%s 手机号码:%s 综合成绩:%s " % (
temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
def paixu():
print("从高到低成绩排序:")
print("序号 学号 姓名 性别 手机号码 综合成绩")
studentthree = []
for temp in student: # 遍历字典的成绩
studentthree.append(temp["score"]) # 将遍历的成绩加入空列表
studentthree.sort(reverse=True) # 将列表的值从大到小排序
for n in studentthree:
i = 0
j = 0
for temp in student:
if temp["score"] == n:
j = 1
break
else:
i = i + 1
if j == 0:
print("没有此学生,查询失败!")
else:
print("%d %s %s %s %s %s" % (
i, temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
def count():
studentfour = []
studentfive = []
for temp in student: # 遍历字典的成绩
studentfour.append(temp["score"]) # 将遍历的成绩加入空列表
a = input("请输入需要统计人数的成绩线(大于该成绩的人数):")
i = 0
for temp in studentfour:
if temp[i] >= a:
studentfive.append(temp[i])
else:
pass
i += 1
print("大于该成绩的人数有:%s" % (len(studentfive)))
def average():
studentsix = []
for temp in student: # 遍历字典的成绩
studentsix.append(temp["score"]) # 将遍历的成绩加入空列表
studentsix = [int(x) for x in studentsix]
tt = sum(studentsix)
pingjun = tt / len(studentsix)
print(pingjun)
def quit():
while True:
d = input("确定退出吗?(Yes or No):")
if d == "Yes":
break
else:
print("输入有误,请重新输入")
def last():
while True:
print_menu()
key = input("请输入功能对应的数字:")
if key == "1":
add()
elif key == "2":
del_info()
elif key == "3":
display()
elif key == "4":
find()
elif key == "5":
change()
elif key == "6":
baocun()
elif key == "7":
findmax()
elif key == "8":
findmin()
elif key == "9":
paixu()
elif key == "10":
count()
elif key == "11":
average()
elif key == "12":
quit()
last()