Why does `Person` call `Animal.__init__(self, age)` by class name instead of just repeating the two lines the parent already wrote?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Person writes its own __init__Cat was happy with the constructor it inherited, because a cat is built from an age alone. A person should be built from a name and an age, and Animal's constructor has no parameter for a name — so Person has to define its own.
Complete the class below so that building a person sets up the age through Animal's own constructor, called the long way on the class name rather than assigning self.age yourself; puts the name in place with the inherited setter set_name; and starts the person off with an empty list stored in self.friends. Then build the person "jack", age 30, and assign him to person.
class Animal(object):
def __init__(self, age):
self.age = age
self.name = None
def get_age(self):
return self.age
def get_name(self):
return self.name
def set_age(self, newage):
self.age = newage
def set_name(self, newname=""):
self.name = newname
def __str__(self):
return "animal:" + str(self.name) + ":" + str(self.age)