1、设计一个类Student,该类包括姓名、学号和成绩。 2、设计一个新增学生成绩的方法,保存:学生姓名、学号和成绩 3、设计一个查询方法 按照成绩从高到低的顺序输出学生姓名、学号、和成绩 4、设计一个删除方法,删除成绩最低的人员信息。
时间: 2024-01-27 18:04:55 浏览: 98
好的,我可以帮你设计一个类Student来实现这些功能。以下是一个示例代码:
```python
class Student:
def __init__(self, name, student_id, score):
self.name = name
self.student_id = student_id
self.score = score
class StudentManagement:
def __init__(self):
self.students = []
def add_score(self, name, student_id, score):
student = Student(name, student_id, score)
self.students.append(student)
def query_scores(self):
sorted_students = sorted(self.students, key=lambda x: x.score, reverse=True)
for student in sorted_students:
print(f"姓名:{student.name},学号:{student.student_id},成绩:{student.score}")
def delete_lowest_score(self):
lowest_score = float('inf')
lowest_student = None
for student in self.students:
if student.score < lowest_score:
lowest_score = student.score
lowest_student = student
if lowest_student:
self.students.remove(lowest_student)
print(f"已删除成绩最低的学生:{lowest_student.name}")
# 示例用法
management = StudentManagement()
management.add_score("张三", "2021001", 80)
management.add_score("李四", "2021002", 90)
management.add_score("王五", "2021003", 75)
management.query_scores()
# 输出:
# 姓名:李四,学号:2021002,成绩:90
# 姓名:张三,学号:2021001,成绩:80
# 姓名:王五,学号:2021003,成绩:75
management.delete_lowest_score()
management.query_scores()
# 输出:
# 姓名:李四,学号:2021002,成绩:90
# 姓名:张三,学号:2021001,成绩:80
```
希望这个示例代码能满足你的需求。如果有其他问题,请随时提问。
阅读全文