Advertisement
adolphuZ

Untitled

Jun 5th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 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. # Przykładowe utworzenie obiektu klasy Osoba
  17. osoba = Osoba("Jan", "Kowalski", 30)
  18. print(osoba.get_name()) # Output: Jan
  19. print(osoba.get_last_name()) # Output: Kowalski
  20. print(osoba.get_age()) # Output: 30
  21.  
  22. class Student(Osoba):
  23. def __init__(self, name, last_name, age, index_nr):
  24. super().__init__(name, last_name, age)
  25. self.index_nr = index_nr
  26.  
  27. def get_index_nr(self):
  28. return self.index_nr
  29.  
  30. # Przykładowe utworzenie obiektu klasy Student
  31. student = Student("Anna", "Nowak", 22, "123456")
  32. print(student.get_name()) # Output: Anna
  33. print(student.get_last_name()) # Output: Nowak
  34. print(student.get_age()) # Output: 22
  35. print(student.get_index_nr()) # Output: 123456
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement