8/19 A Methodical Approach description of exercise is unclear


#1

The exercise instructs me to write something like this:

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    def __init__(self, name, age):
        self.name = name
        self.age = age
    # Add your method here!
    def __init__(self, description):
        self.description = description

print Animal.name
print Animal.age

hippo = Animal("Jeffrey", 2)

The problem is that the code doesn't work, claiming that Animal.name does not exist. What did I do wrong?


#2

Hi they aske you to..
Add a method, description, to your Animal class.

class Animal(object):
    ....
    def description(self):

Using two separate print statements(should be inside the method description), it should print out the name and age of the animal it's called on. so you should do it like that

class Animal(object):
    ....
    def description(self):
        print self.name
        print self.age

Then, create an instance of Animal, hippo (with whatever name and age you like), and call its description method. and you did it

hippo = Animal("Jeffrey", 2)

then it's only missing the call of the method description on hippo
Hope that could help you


#3

Yep, that worked. Thanks!

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    health = "good"
    def __init__(self, name, age):
        self.name = name
        self.age = age
    # Add your method here!
    def description(self):
        print self.name
        print self.age

hippo = Animal("Jeffrey", 2)
sloth = Animal("Shotgun", 3)
ocelot = Animal("Shalashaska", 5)

print hippo.health
print sloth.health
print ocelot.health