BdW44222

5. Class

Jul 1st, 2021
924
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Class:
  2.     __student_count = 22
  3.  
  4.     def __init__(self, name):
  5.         self.name = name
  6.         self.students = []
  7.         self.grades = []
  8.  
  9.     def add_student(self, name, grade):
  10.         if len(self.students) < Class.__student_count:
  11.             self.students.append(name)
  12.             self.grades.append(grade)
  13.  
  14.     def get_average_grade(self):
  15.         return sum(self.grades) / len(self.grades)
  16.  
  17.     def __repr__(self):
  18.         grade = self.get_average_grade()
  19.         result = f"The students in {self.name}: " \
  20.                  f"{', '.join(self.students)}. " \
  21.                  f"Average grade: {grade:.2f}"
  22.         return result
  23.  
RAW Paste Data