帮我写一段学生成绩管理系统python代码
时间: 2023-08-28 11:32:21 浏览: 83
学生成绩管理系统python
5星 · 资源好评率100%
当然可以!以下是一个简单的学生成绩管理系统的 Python 代码示例:
```python
class Student:
def __init__(self, name, scores):
self.name = name
self.scores = scores
class GradeBook:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def get_student_average(self, student):
return sum(student.scores) / len(student.scores)
def get_class_average(self):
total_scores = 0
num_students = len(self.students)
for student in self.students:
total_scores += sum(student.scores)
return total_scores / (num_students * len(student.scores))
# Example usage:
bob = Student("Bob", [90, 80, 70])
jane = Student("Jane", [95, 85, 75])
gradebook = GradeBook()
gradebook.add_student(bob)
gradebook.add_student(jane)
bob_average = gradebook.get_student_average(bob)
jane_average = gradebook.get_student_average(jane)
class_average = gradebook.get_class_average()
print("Bob's average score:", bob_average)
print("Jane's average score:", jane_average)
print("Class average score:", class_average)
```
这个代码定义了两个类:`Student` 和 `GradeBook`。`Student` 类包含学生的姓名和分数,`GradeBook` 类管理学生列表并提供方法来计算学生和整个班级的平均分数。你可以根据自己的需要进行修改和扩展。
阅读全文