...

/

Solution Review 2: Implement an Animal Class

Solution Review 2: Implement an Animal Class

This lesson provides a solution review for the `Implement an Animal Class` challenge.

We'll cover the following...

Solution #

class Animal:
def __init__(self, name, sound):
self.name = name
self.sound = sound
def Animal_details(self):
print("Name:", self.name)
print("Sound:", self.sound)
class Dog(Animal):
def __init__(self, name, sound, family):
super().__init__(name, sound)
self.family = family
def Animal_details(self):
super().Animal_details()
print("Family:", self.family)
class Sheep(Animal):
def __init__(self, name, sound, color):
super().__init__(name, sound)
self.color = color
def Animal_details(self):
super().Animal_details()
print("Color:", self.color)
d = Dog("Pongo", "Woof Woof", "Husky")
d.Animal_details()
print("")
s = Sheep("Billy", "Baa Baa", "White")
s.Animal_details()

Explanation

  • We implemented an Animal class, which has name and sound ...