|
@@ -0,0 +1,50 @@
|
|
|
+
|
|
|
+
|
|
|
+class Mammal:
|
|
|
+
|
|
|
+ def __init__(self, species) -> None:
|
|
|
+ self.__species = species
|
|
|
+
|
|
|
+ def show_species(self):
|
|
|
+ print('Я -', self.__species)
|
|
|
+
|
|
|
+ def make_sound(self):
|
|
|
+ print('Гррррррр')
|
|
|
+
|
|
|
+class Dog(Mammal):
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ Mammal.__init__(self, 'собака')
|
|
|
+
|
|
|
+ def make_sound(self):
|
|
|
+ print('Гав-гав!')
|
|
|
+
|
|
|
+class Cat(Mammal):
|
|
|
+
|
|
|
+ def __init__(self) -> None:
|
|
|
+ Mammal.__init__(self, 'кот')
|
|
|
+
|
|
|
+ def make_sound(self):
|
|
|
+ print('Мяу!')
|
|
|
+
|
|
|
+
|
|
|
+def show_mammal_info(creature):
|
|
|
+ if isinstance(creature, Mammal):
|
|
|
+ creature.show_species()
|
|
|
+ creature.make_sound()
|
|
|
+ else:
|
|
|
+ print('Это не млекопитающее!')
|
|
|
+
|
|
|
+
|
|
|
+def main():
|
|
|
+ animal = Mammal('обычное эивотное')
|
|
|
+ dog = Dog()
|
|
|
+ cat = Cat()
|
|
|
+
|
|
|
+ show_mammal_info(animal)
|
|
|
+ show_mammal_info(dog)
|
|
|
+ show_mammal_info(cat)
|
|
|
+ show_mammal_info('asdfsd')
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|