Advertisement
adolphuZ

Untitled

Jun 5th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 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. # Przykładowa inicjalizacja dwóch studentów z ocenami z więcej niż trzech przedmiotów
  39.  
  40. grades_student1 = {
  41.     "Mathematics": 5,
  42.     "Physics": 4,
  43.     "Chemistry": 3,
  44.     "Biology": 4
  45. }
  46.  
  47. grades_student2 = {
  48.     "Mathematics": 4,
  49.     "Physics": 5,
  50.     "Chemistry": 4,
  51.     "History": 3
  52. }
  53.  
  54. student1 = Student("Anna", "Nowak", 22, "123456", grades_student1)
  55. student2 = Student("Piotr", "Kowalski", 23, "789012", grades_student2)
  56.  
  57. # Wyświetlenie danych studentów
  58. print(f"Student 1: {student1.get_name()} {student1.get_last_name()}, Age: {student1.get_age()}, Index: {student1.get_index_nr()}")
  59. print("Grades:", student1.get_notes())
  60.  
  61. print(f"Student 2: {student2.get_name()} {student2.get_last_name()}, Age: {student2.get_age()}, Index: {student2.get_index_nr()}")
  62. print("Grades:", student2.get_notes())
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement