from abc import ABCMeta, abstractmethod class Animal(metaclass=ABCMeta): #1 Mark for implementing the generic attributes that apply to all other classes def __init__(self): self._coldBlooded = False self._skinType = None self._tail = False self._legs = 0 self._arms = 0 self._wings = 0 #1 Mark for creating an abstract move method @abstractmethod def move(self): pass #1 Mark for creating an abstract eat method @abstractmethod def eat(self): pass #1 Mark for creating an abstract birth method @abstractmethod def birth(self): pass #1 Mark for implementing the generic aspects of getInfo that apply to all other classes @abstractmethod def getInfo(self): if self._coldBlooded: print("This animal is cold-blooded") else: print("This animal is warm-blooded") if self._skinType != None: print("This animal is covered in " + self._skinType) if self._tail: print("This animal has a tail") if self._legs > 0: print("This animal has " + str(self._legs) + " legs") if self._arms > 0: print("This animal has " + str(self._arms) + " arms") if self._wings > 0: print("This animal has " + str(self._wings) + " wings") self.move() self.eat() self.birth() #1 Mark for inheriting from Animal class Reptile(Animal): #1 Mark for setting appropriate default values for attributes def __init__(self): super().__init__() self._coldBlooded = True self._skinType = "scales" self._legs = 4 self._tail = True #1 Mark for implementing birth for reptiles def birth(self): print("This animal lays eggs") #1 Mark for implementing hibernate for reptiles def hibernate(self): print("This animal hibernates") #1 Mark for calling super method and adding call to hibernate def getInfo(self): super().getInfo() self.hibernate() #1 Mark for inheriting from Animal class Mammal(Animal): #1 Mark for setting appropriate default values for attributes def __init__(self): super().__init__() self._skinType = "fur" #1 Mark for implementing birth for mammals def birth(self): print("This animal gives birth to live young") #1 Mark for avoiding code repetition between child and parent classes #1 Mark for implementing move and eat in all of the following classes #1 Mark for inheriting the appropriate parent class in all of the following classes class Tortoise(Reptile): def move(self): print("This animal walks") def eat(self): print("This animal is a herbivore") def getInfo(self): print("Tortoise:") super().getInfo() print() class Turtle(Reptile): def move(self): print("This animal crawls and swims") def eat(self): print("This animal is an omnivore") def getInfo(self): print("Turtle:") super().getInfo() print() class Snake(Reptile): def __init__(self): super().__init__() self._legs = 0 def move(self): print("This animal slithers") def eat(self): print("This animal is a carnivore") def getInfo(self): print("Snake:") super().getInfo() print() class Otter(Mammal): def __init__(self): super().__init__() self._legs = 4 self._tail = True def move(self): print("This animal walks and swims") def eat(self): print("This animal is an omnivore") def getInfo(self): print("Otter:") super().getInfo() print() class Gorilla(Mammal): def __init__(self): super().__init__() self._legs = 2 self._arms = 2 def move(self): print("This animal walks and climbs") def eat(self): print("This animal is a herbivore") def getInfo(self): print("Gorilla:") super().getInfo() print() class Bat(Mammal): def __init__(self): super().__init__() self._legs = 2 self._tail = True self._wings = 2 def move(self): print("This animal flies") def eat(self): print("This animal is an omnivore") #1 Mark for adding hibernate in Bat def hibernate(self): print("This animal hibernates") def getInfo(self): print("Bat:") super().getInfo() self.hibernate() print() def main(): tortoise = Tortoise() turtle = Turtle() snake = Snake() otter = Otter() gorilla = Gorilla() bat = Bat() tortoise.getInfo() turtle.getInfo() snake.getInfo() otter.getInfo() gorilla.getInfo() bat.getInfo() input() if __name__ == '__main__': main()