Advertisement
go6odn28

5_class

Feb 24th, 2024
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. class Class:
  2.     __students_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: str, grade: float):
  10.         if self.__students_count > len(self.students):
  11.             self.students.append(name)
  12.             self.grades.append(grade)
  13.  
  14.     def get_average_grade(self):
  15.         average_grade = sum(self.grades) / len(self.grades)
  16.         return round(average_grade, 2)
  17.  
  18.     def __repr__(self):
  19.         return f"The students in {self.name}: {', '.join(self.students)}. Average grade: {self.get_average_grade()}"
  20.  
  21.  
  22. a_class = Class("11B")
  23. a_class.add_student("Peter", 4.80)
  24. a_class.add_student("George", 6.00)
  25. a_class.add_student("Amy", 3.50)
  26. print(a_class)
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement