用python写一个学生成绩管理系统,包括成绩录入,成绩显示,成绩查询,成绩排序(按总分),成绩修改,成绩统计,退出系统
时间: 2024-06-09 19:07:25 浏览: 108
python语言实现学生成绩管理系统
5星 · 资源好评率100%
好的,下面是一个简单的学生成绩管理系统的代码实现:
```python
students = [] # 存储学生信息
# 添加学生信息
def add_student():
name = input("请输入学生姓名:")
math_score = int(input("请输入数学成绩:"))
english_score = int(input("请输入英语成绩:"))
chinese_score = int(input("请输入语文成绩:"))
total_score = math_score + english_score + chinese_score
student = {"name": name, "math_score": math_score,
"english_score": english_score, "chinese_score": chinese_score,
"total_score": total_score}
students.append(student)
print("添加成功!")
# 显示学生信息
def show_students():
if len(students) == 0:
print("暂无学生信息!")
else:
print("姓名\t数学\t英语\t语文\t总分")
for student in students:
print(student["name"], "\t", student["math_score"], "\t",
student["english_score"], "\t", student["chinese_score"], "\t",
student["total_score"])
# 查询学生信息
def search_student():
name = input("请输入要查询的学生姓名:")
for student in students:
if student["name"] == name:
print("姓名\t数学\t英语\t语文\t总分")
print(student["name"], "\t", student["math_score"], "\t",
student["english_score"], "\t", student["chinese_score"], "\t",
student["total_score"])
return
print("未找到该学生信息!")
# 按总分排序
def sort_students():
students.sort(key=lambda x:x["total_score"], reverse=True)
show_students()
# 修改学生信息
def modify_student():
name = input("请输入要修改的学生姓名:")
for student in students:
if student["name"] == name:
math_score = int(input("请输入数学成绩:"))
english_score = int(input("请输入英语成绩:"))
chinese_score = int(input("请输入语文成绩:"))
total_score = math_score + english_score + chinese_score
student["math_score"] = math_score
student["english_score"] = english_score
student["chinese_score"] = chinese_score
student["total_score"] = total_score
print("修改成功!")
return
print("未找到该学生信息!")
# 统计学生信息
def statistics_students():
math_total = 0
english_total = 0
chinese_total = 0
for student in students:
math_total += student["math_score"]
english_total += student["english_score"]
chinese_total += student["chinese_score"]
print("总人数:", len(students))
print("数学平均分:", math_total/len(students))
print("英语平均分:", english_total/len(students))
print("语文平均分:", chinese_total/len(students))
# 退出系统
def exit_system():
print("感谢使用!")
exit()
# 主函数
def main():
while True:
print("欢迎使用学生成绩管理系统!")
print("1.添加学生信息")
print("2.显示学生信息")
print("3.查询学生信息")
print("4.按总分排序")
print("5.修改学生信息")
print("6.统计学生信息")
print("7.退出系统")
choice = int(input("请输入您的选择:"))
if choice == 1:
add_student()
elif choice == 2:
show_students()
elif choice == 3:
search_student()
elif choice == 4:
sort_students()
elif choice == 5:
modify_student()
elif choice == 6:
statistics_students()
elif choice == 7:
exit_system()
else:
print("输入有误,请重新输入!")
if __name__ == '__main__':
main()
```
这个学生成绩管理系统支持添加学生信息、显示学生信息、查询学生信息、按总分排序、修改学生信息、统计学生信息、退出系统等功能。你可以根据自己的需要进行修改和扩展。
阅读全文