Advertisement
programusy

Untitled

Feb 8th, 2023
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2.  
  3. class Animal(ABC):
  4. def __init__(self, name, description):
  5. self.name = name
  6. self.description = description
  7.  
  8. @abstractmethod
  9. def display_info(self):
  10. pass
  11.  
  12. class Dog(Animal):
  13. def __init__(self, name, description, breed, weight):
  14. Animal.__init__(self, name, description)
  15. self.breed = breed
  16. self.weight = weight
  17.  
  18. def display_info(self):
  19. print("Name: ", self.name)
  20. print("Description: ", self.description)
  21. print("Breed: ", self.breed)
  22. print("Weight: ", self.weight)
  23.  
  24. class Bird(Animal):
  25. def __init__(self, name, description, color, weight):
  26. Animal.__init__(self, name, description)
  27. self.color = color
  28. self.weight = weight
  29.  
  30. def display_info(self):
  31. print("Name: ", self.name)
  32. print("Description: ", self.description)
  33. print("Color: ", self.color)
  34. print("Weight: ", self.weight)
  35.  
  36. dog1 = Dog("Ass", "Doberman", "Doberman", 30)
  37. dog2 = Dog("Asik", "Jamnik", "Terrier", 15)
  38. bird1 = Bird("Papuga", "Parrot", "Green", 1)
  39. bird2 = Bird("Kanarek", "Canary", "Yellow", 0.5)
  40.  
  41. dog1.display_info()
  42. print()
  43. dog2.display_info()
  44. print()
  45. bird1.display_info()
  46. print()
  47. bird2.display_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement