Advertisement
VssA

animals

Oct 31st, 2023
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. class Animal:
  2.     def __init__(self, weight, age, sound):
  3.         self.animal_sound = sound
  4.         self.weight = weight
  5.         self.age = age
  6.  
  7.     def pet(self):
  8.         print('happy sounds')
  9.  
  10.     def info(self):
  11.         print(f"вес животного = {self.weight}, возраст = {self.age}, что говорит питомец = {self.animal_sound}")
  12.  
  13.  
  14. class Dog(Animal):
  15.     def __init__(self, weight=0, age=0, sound="", breed=""):
  16.         super().__init__(weight, age, sound)
  17.         self.breed = breed
  18.  
  19.     def which_breed(self):
  20.         print(self.breed)
  21.  
  22.  
  23. class Cat(Animal):
  24.     def __init__(self, weight=0, age=0, sound="", color=""):
  25.         super().__init__(weight, age, sound)
  26.         self.color = color
  27.  
  28.     def which_color(self):
  29.         print(self.color)
  30.  
  31.  
  32. class Elephant(Animal):
  33.     def __init__(self, weight=0, age=0, sound="", ears_size=0):
  34.         super().__init__(weight, age, sound)
  35.         self.ears_size = ears_size
  36.  
  37.     def ears(self):
  38.         print(self.ears_size)
  39.  
  40.  
  41. if __name__ == "__main__":
  42.     cat = Cat(2, 2, 'MEOW', 'black')
  43.     print(cat.info())
  44.     print(f"цвет кошки: {cat.color}")
  45.  
  46.     dog = Dog(2, 2, 'BARK', 'shepherd')
  47.     print(dog.info())
  48.     print(f"порода собаки: {dog.breed}")
  49.  
  50.     elephant = Elephant(200, 7, 'ELEPHANT_SOUND', 20)
  51.     print(elephant.info())
  52.     print(f"{elephant.ears_size}")
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement