以下是一个简单的学生作业成绩管理系统的Python代码实现,具体实现可能因实际需求而有所不同:
```python
class Student:
def __init__(self, course, classroom, student_id, name):
self.course = course
self.classroom = classroom
self.student_id = student_id
self.name = name
self.scores = [0] * 10
self.total_score = 0
def set_score(self, index, score):
self.scores[index] = score
def calc_total_score(self):
self.total_score = sum(self.scores) / 10.0
def __str__(self):
return f"{self.student_id}\t{self.name}\t{self.total_score:.1f}"
class ScoreManager:
def __init__(self):
self.students = {}
def add_student(self, course, classroom, student_id, name):
self.students[student_id] = Student(course, classroom, student_id, name)
def set_score(self, student_id, index, score):
self.students[student_id].set_score(index, score)
def calc_total_scores(self):
for student in self.students.values():
student.calc_total_score()
def query_student(self, student_id):
return self.students.get(student_id)
def query_students_by_name(self, name):
return [student for student in self.students.values() if student.name == name]
def query_students_by_classroom(self, classroom):
return [student for student in self.students.values() if student.classroom == classroom]
def query_students_by_index_score(self, index):
return sorted(self.students.values(), key=lambda x: x.scores[index], reverse=True)
def query_students_by_total_score(self):
return sorted(self.students.values(), key=lambda x: x.total_score, reverse=True)
```
使用方法示例:
```python
manager = ScoreManager()
# 添加学生
manager.add_student("Math", "Class A", "001", "Tom")
manager.add_student("Math", "Class A", "002", "Jerry")
# 录入分数
manager.set_score("001", 0, 80)
manager.set_score("001", 1, 90)
manager.set_score("001", 2, 70)
manager.set_score("002", 0, 85)
manager.set_score("002", 1, 95)
manager.set_score("002", 2, 75)
# 计算总评成绩
manager.calc_total_scores()
# 查询学生信息
student = manager.query_student("001")
print(student) # 001 Tom 8.0
students = manager.query_students_by_name("Jerry")
for student in students:
print(student) # 002 Jerry 8.5
students = manager.query_students_by_classroom("Class A")
for student in students:
print(student) # 001 Tom 8.0
# 002 Jerry 8.5
students = manager.query_students_by_index_score(0)
for student in students:
print(student) # 002 Jerry 8.5
# 001 Tom 8.0
students = manager.query_students_by_total_score()
for student in students:
print(student) # 002 Jerry 8.5
# 001 Tom 8.0
```