Advertisement
adolphuZ

Untitled

Jun 5th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. class Osoba:
  2.     def __init__(self, name, last_name, age):
  3.         self.name = name
  4.         self.last_name = last_name
  5.         self.age = age
  6.  
  7.     def get_name(self):
  8.         return self.name
  9.  
  10.     def get_last_name(self):
  11.         return self.last_name
  12.  
  13.     def get_age(self):
  14.         return self.age
  15.  
  16. class Note:
  17.     def __init__(self, grades):
  18.         self.grades = grades
  19.  
  20.     def get_grades(self):
  21.         return self.grades
  22.  
  23.     def get_grade(self, subject):
  24.         return self.grades.get(subject, None)
  25.  
  26. class Student(Osoba):
  27.     def __init__(self, name, last_name, age, index_nr, grades):
  28.         super().__init__(name, last_name, age)
  29.         self.index_nr = index_nr
  30.         self.notes = Note(grades)
  31.  
  32.     def get_index_nr(self):
  33.         return self.index_nr
  34.  
  35.     def get_notes(self):
  36.         return self.notes.get_grades()
  37.  
  38. class Group:
  39.     def __init__(self):
  40.         self.students = []
  41.  
  42.     def add_student(self, student):
  43.         self.students.append(student)
  44.  
  45.     def get_students(self):
  46.         return self.students
  47.  
  48.     def display_students(self):
  49.         for student in self.students:
  50.             print(f"Student: {student.get_name()} {student.get_last_name()}, Age: {student.get_age()}, Index: {student.get_index_nr()}")
  51.             print(f"Grades: {student.get_notes()}")
  52.  
  53. # Przykładowa inicjalizacja studentów
  54. grades_student1 = {
  55.     "Mathematics": 5,
  56.     "Physics": 4,
  57.     "Chemistry": 3
  58. }
  59.  
  60. grades_student2 = {
  61.     "Mathematics": 4,
  62.     "Physics": 5,
  63.     "Chemistry": 4
  64. }
  65.  
  66. student1 = Student("Anna", "Nowak", 22, "2021001", grades_student1)
  67. student2 = Student("Piotr", "Kowalski", 23, "2021002", grades_student2)
  68.  
  69. # Przykładowa inicjalizacja grupy z dowolnymi studentami
  70. group = Group()
  71. group.add_student(student1)
  72. group.add_student(student2)
  73.  
  74. # Wyświetlenie studentów w grupie
  75. group.display_students()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement