1.添加学生信息
2.修改学生信息
3.删除学生
4.添加学生的成绩
5.修改学生成绩
6.按姓名或者学号查找学生,显示学生信息及三门课的成绩,以及排名
7.学生成绩统计(每门课的平均分、最高分、最低分)
#coding = utf-8
students=[]
def showInfo():
print(" 学生管理系统")
print(" 1.添加学生的信息")
print(" 2.修改学生的信息")
print(" 3.删除学生的信息")
print(" 4.添加学生的成绩")
print(" 5.修改学生成绩")
print(" 6.查找学生信息")
print(" 7.学生成绩统计")
print(" 8.退出")
def add_student():
print("请添加学生姓名学号")
name = input("请输入学生姓名")
stuId = input("请输入学生学号(学号不可重复)")
age = input("请输入学生年龄")
##验证学号是否唯一
leap = 0
for temp in students:
if temp['id'] == stuId:
leap = 1
break
if leap == 1:
print("输入学生学号重复,添加失败!")
return 0
else:
# 定义一个字典,存放单个学生信息
stuInfo = {}
stuInfo['name'] = name
stuInfo['id'] = stuId
stuInfo['age'] = age
stuInfo['Machine_learning'] = 0
stuInfo['Python_score'] = 0
stuInfo['English_score'] = 0
# 单个学生信息放入列表
students.append(stuInfo)
print("添加成功!")
def revise_student():
alterId = input("请输入你要修改学生的学号:")
# 检测是否有此学号,然后进行修改信息
i = 0
leap = 0
for temp in students:
if temp['id'] == alterId:
leap = 1
break
else:
i = i + 1
if leap == 1:
while True:
alterNum = int(input(" 1.修改学号\n 2.修改姓名 \n 3.修改年龄 \n 4.退出修改\n"))
if alterNum == 1:
newId = input("输入更改后的学号:")
# 修改后的学号要验证是否唯一
i = 0
leap1 = 0
for temp1 in students:
if temp1['id'] == newId:
leap1 = 1
break
else:
i = i + 1
if leap1 == 1:
print("输入学号不可重复,修改失败!")
else:
temp['id'] = newId
print("学号修改成功")
elif alterNum == 2:
newName = input("输入更改后的姓名:")
temp['name'] = newName
print("姓名修改成功")
elif alterNum == 3:
newAge = input("输入更改后的年龄:")
temp['age'] = newAge
print("年龄修改成功")
elif alterNum == 4:
break
else:
print("输入错误请重新输入")
else:
print("没有此学号,修改失败!")
def delete_student():
delId = input("请输入要删除的学生学号:")
# i记录要删除的下标,leap为标志位,如果找到leap=1,否则为0
i = 0
leap = 0
for temp in students:
if temp['id'] == delId:
leap = 1
break
else:
i = i + 1
if leap == 0:
print("没有此学生学号,删除失败!")
else:
del students[i]
print("删除成功!")
def add_student_score():
print("添加学生成绩")
stuId = input("请选择学生学号")
i = 0
leap = 0
for temp in students:
if temp['id'] == stuId:
leap = 1
break
else:
i = i+1
if leap == 1:
while True:
num = int(input(" 1.机器学习成绩\n 2.Python程序设计 \n 3.研究生英语 \n 4.退出修改\n"))
if num == 1:
Machine_learning = input("机器学习的成绩")
temp['Machine_learning'] = Machine_learning
elif num == 2:
Python_score = input("Python程序设计成绩")
temp['Python_score'] = Python_score
elif num == 3:
English_score = input("研究生英语成绩")
temp['English_score'] = English_score
elif num == 4:
break
def search_student():
SearchStuId = input("请输入查找的学号")
leap = 0
for temp in students:
if temp['id'] == SearchStuId:
leap = 1
break
if leap == 0:
print("没有此学生学号,查询失败!")
else:
print("找到此学生,信息如下:")
print("学号:%s\n姓名:%s\n年龄:%s\n" % (temp['id'], temp['name'], temp['age']))
print("各科成绩:\n 机器学习:%s\nPython程序设计:%s\n研究生英语:%s" %(temp['Machine_learning'],temp['Python_score'],temp['English_score']))
def revise_student_score():
alterId = input("请输入你要修改学生的学号:")
# 检测是否有此学号,然后进行修改信息
i = 0
leap = 0
for temp in students:
if temp['id'] == alterId:
leap = 1
break
else:
i = i + 1
if leap == 1:
while True:
alterNum = int(input(" 1.修改机器学习成绩\n 2.修改Python成绩 \n 3.修改英语成绩 \n 4.退出修改\n"))
if alterNum == 1:
NewMachine_learning = input("机器学习成绩")
temp['Machine_learning'] = NewMachine_learning
elif alterNum == 2:
NewPython_score = input("Python成绩")
temp['Python_score'] = NewPython_score
elif alterNum == 3:
NewEnglish_score = input("英语成绩")
temp['English_score'] = NewEnglish_score
elif alterNum == 4:
break
def student_score_count():
Machine_learning_score = 0
Python_score = 0
English_score = 0
a=0
for temp in students:
Machine_learning_score += int(temp['Machine_learning'])
Python_score += int(temp['Python_score'])
English_score += int(temp['English_score'])
a+=1
Machine_learning_score_age = Machine_learning_score/a
Python_score_age = Python_score/a
English_score_age = English_score/a
print("机器学习平均成绩", Machine_learning_score_age)
print("Pythong平均成绩", Python_score_age)
print("英语平均成绩", English_score_age)
high_machine_learning = 0
for temp in students:
machine_learning = int(temp['Machine_learning'])
if machine_learning>high_machine_learning:
high_machine_learning = machine_learning
print("机器学习的最高分",high_machine_learning)
high_python = 0
for temp in students:
python = int(temp['Python_score'])
if python>high_python:
high_python = python
print("Python的最高分",high_python)
high_english = 0
for temp in students:
english = int(temp['English_score'])
if english > high_english:
high_english = english
print("英语的最高分", high_english)
low_machine_learning = 1000000
for temp in students:
machine_learning = int(temp['Machine_learning'])
if machine_learning < low_machine_learning:
low_machine_learning = machine_learning
print("机器学习的最低分", low_machine_learning)
low_python = 1000000
for temp in students:
python = int(temp['Python_score'])
if python < low_python:
low_python = python
print("Python的最低分", low_python)
low_english = 1000000
for temp in students:
english = int(temp['English_score'])
if english < low_english:
low_english = english
print("英语的最低分", low_english)
while True :
showInfo()
num = int(input("请选择功能"))
if num==1:
# 添加学生的信息
add_student()
elif num==2:
# 修改学生的信息
revise_student()
elif num==3:
# 删除学生的信息
delete_student()
elif num==4:
# 添加学生的成绩
add_student_score()
elif num==5:
# 修改学生成绩
revise_student_score()
elif num==6:
# 查找学生信息
search_student()
elif num==7:
# 学生成绩统计
student_score_count()
elif num==8:
break