Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Class:
- __students_count = 22
- def __init__(self, name):
- self.name = name
- self.students = []
- self.grades = []
- def add_student(self, name: str, grade: float):
- if self.__students_count > len(self.students):
- self.students.append(name)
- self.grades.append(grade)
- def get_average_grade(self):
- average_grade = sum(self.grades) / len(self.grades)
- return round(average_grade, 2)
- def __repr__(self):
- return f"The students in {self.name}: {', '.join(self.students)}. Average grade: {self.get_average_grade()}"
- a_class = Class("11B")
- a_class.add_student("Peter", 4.80)
- a_class.add_student("George", 6.00)
- a_class.add_student("Amy", 3.50)
- print(a_class)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement