用python写学生成绩管理系统包含输入并存储学生的信息 ,修改学生信息 ,删除学生信息 ,成绩排序 ,查找学生信息
时间: 2023-06-12 15:04:07 浏览: 156
好的,下面是一个简单的学生成绩管理系统示例代码:
```python
class Student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
class StudentGradeSystem:
def __init__(self):
self.students = []
def add_student(self, name, grade):
student = Student(name, grade)
self.students.append(student)
def remove_student(self, name):
for student in self.students:
if student.name == name:
self.students.remove(student)
def update_student(self, name, grade):
for student in self.students:
if student.name == name:
student.grade = grade
def sort_students(self):
self.students = sorted(self.students, key=lambda x: x.grade, reverse=True)
def search_student(self, name):
for student in self.students:
if student.name == name:
return student
def print_students(self):
for student in self.students:
print(f"{student.name}: {student.grade}")
system = StudentGradeSystem()
# 添加学生信息
system.add_student("张三", 90)
system.add_student("李四", 80)
system.add_student("王五", 70)
# 输出学生信息
system.print_students()
# 修改学生信息
system.update_student("李四", 85)
# 删除学生信息
system.remove_student("王五")
# 排序并输出学生信息
system.sort_students()
system.print_students()
# 查找学生信息
student = system.search_student("张三")
if student:
print(f"{student.name} 的成绩是 {student.grade}")
else:
print("没有找到该学生信息")
```
这份代码实现了添加学生信息、修改学生信息、删除学生信息、成绩排序和查找学生信息的功能。你可以根据自己的需求进行修改和扩展。
阅读全文