36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
from animal import Animal
|
|
|
|
|
|
class Mammal(Animal): # <1>
|
|
def __init__(self, species, name, sound, gestation):
|
|
super(Mammal, self).__init__(species, name, sound)
|
|
self._gestation = gestation
|
|
|
|
@property
|
|
def gestation(self): # <2>
|
|
"""Length of gestation period in days"""
|
|
return self._gestation
|
|
|
|
|
|
if __name__ == "__main__":
|
|
mammal1 = Mammal("African lion", "Bob", "Roarrrr", 120)
|
|
print(mammal1.name, "is a", mammal1.species, "--", end=' ')
|
|
mammal1.make_sound()
|
|
|
|
print("Number of animals", mammal1.zoo_size())
|
|
|
|
mammal2 = Mammal("Fruit bat", "Freddie", "Squeak!!", 180)
|
|
print(mammal2.name, "is a", mammal2.species, "--", end=' ')
|
|
mammal2.make_sound()
|
|
|
|
print("Number of animals", mammal2.zoo_size())
|
|
print("Number of animals", Mammal.zoo_size())
|
|
|
|
mammal1.kill()
|
|
print("Number of animals", Mammal.zoo_size())
|
|
|
|
print("Gestation period of the", mammal1.species, "is", mammal1.gestation, "days")
|
|
print("Gestation period of the", mammal2.species, "is", mammal2.gestation, "days")
|