Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal:
- def __init__(self, weight, age, sound):
- self.animal_sound = sound
- self.weight = weight
- self.age = age
- def pet(self):
- print('happy sounds')
- def info(self):
- print(f"вес животного = {self.weight}, возраст = {self.age}, что говорит питомец = {self.animal_sound}")
- class Dog(Animal):
- def __init__(self, weight=0, age=0, sound="", breed=""):
- super().__init__(weight, age, sound)
- self.breed = breed
- def which_breed(self):
- print(self.breed)
- class Cat(Animal):
- def __init__(self, weight=0, age=0, sound="", color=""):
- super().__init__(weight, age, sound)
- self.color = color
- def which_color(self):
- print(self.color)
- class Elephant(Animal):
- def __init__(self, weight=0, age=0, sound="", ears_size=0):
- super().__init__(weight, age, sound)
- self.ears_size = ears_size
- def ears(self):
- print(self.ears_size)
- if __name__ == "__main__":
- cat = Cat(2, 2, 'MEOW', 'black')
- print(cat.info())
- print(f"цвет кошки: {cat.color}")
- dog = Dog(2, 2, 'BARK', 'shepherd')
- print(dog.info())
- print(f"порода собаки: {dog.breed}")
- elephant = Elephant(200, 7, 'ELEPHANT_SOUND', 20)
- print(elephant.info())
- print(f"{elephant.ears_size}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement