python学生管理系统排序成绩代码
时间: 2024-02-10 11:08:15 浏览: 158
学生成绩管理系统的代码
5星 · 资源好评率100%
以下是一个示例的Python学生管理排序成绩的代码:
```python
# 定义学生类
class Student:
def __init__(self, student_id, name, score):
self.student_id = studen_id
self.name = name
self.score = score
# 创建学生列表
students = []
# 输入学生信息
def input_student_info():
student_id = input("请输入学生学号:")
name = input("请输入学生姓名:")
score = float(input("请输入学生成绩:"))
student = Student(student_id, name, score)
students.append(student)
# 按英语成绩排序
def sort_by_english_score():
sorted_students = sorted(students, key=lambda x: x.score)
for student in sorted_students:
print("学号:{},姓名:{},英语成绩:{}".format(student.student_id, student.name, student.score))
# 按数学成绩排序
def sort_by_math_score():
sorted_students = sorted(students, key=lambda x: x.score)
for student in sorted_students:
print("学号:{},姓名:{},数学成绩:{}".format(student.student_id, student.name, student.score))
# 按Python成绩排序
def sort_by_python_score():
sorted_students = sorted(students, key=lambda x: x.score)
for student in sorted_students:
print("学号:{},姓名:{},Python成绩:{}".format(student.student_id, student.name, student.score))
# 主程序
def main():
while True:
op = input("输入1按英语成绩排序,输入2按数学成绩排序,输入3按Python成绩排序:")
if op == "1":
sort_by_english_score()
elif op == "2":
sort_by_math_score()
elif op == "3":
sort_by_python_score()
else:
print("输入无效,请重新输入!")
if __name__ == "__main__":
main()
```
阅读全文