python class Student: def __init__(self, name, age): self.name = name self.age = age self.scores = [] def add_score(self, score): self.scores.append(score) def calculate_average_score(self): if len(self.scores) == 0: return 0 total = sum(self.scores) return total / len(self.scores) def __str__(self): return f"Name: {self.name}, Age: {self.age}" python class StudentManagementSystem: def __init__(self): self.students = [] def add_student(self, student): self.students.append(student) def find_student(self, name): for student in self.students: if student.name == name: return student return None def calculate_class_average(self): total_score = 0 count = 0 for student in self.students: total_score += student.calculate_average_score() count += 1 return total_score / count python sms = StudentManagementSystem() sms.add_student(student1) sms.add_student(student2) student1.add_score(80) student1.add_score(90) student2.add_score(85) student2.add_score(75) if found_student: print(found_student) print(f"Average score: {found_student.calculate_average_score()}") else: print("Student not found") class_average = sms.calculate_class_average() print(f"Class average: {class_average}")


上一篇:
下一篇:
切换中文