Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal:
- """parent class for all animals"""
- def __init__(self, name, weight, color, noise):
- """initialies an Animal instance"""
- self.__name = name
- self.weight = weight
- self.__color = color
- self.__noise = noise
- def make_noise(self):
- print(self.__noise)
- def eat(self, food):
- print('munch... munch...')
- @property
- def color(self):
- return self.__color
- @property
- def name(self):
- return self.__name
- @name.setter
- def name(self, new_name):
- print('changed name')
- self.__name = new_name
- def __del__(self):
- print("bye")
- class Carnivore:
- def eat(self, food):
- if isinstance(food, Animal):
- food.make_noise()
- super().eat(food)
- class TRex(Carnivore, Animal):
- def __init__(self, name, weight, color):
- super().__init__(name, weight, color, 'ROOAAAARR!!!!!!!!!')
- class Dog(Animal):
- def __init__(self, name, weight, color):
- super().__init__(name, weight, color, 'woof')
- class Horse(Animal):
- def __init__(self, name, weight, color):
- super().__init__(name, weight, color, 'neeeehh')
- class Squirrel(Animal):
- def __init__(self, name, weight, color):
- super().__init__(name, weight, color, 'squeek')
Add Comment
Please, Sign In to add comment