9. They're Multiplying!


#1

Can anyone help me with this type of confusing mistake "Oops, try again. Did you create an Animal() called sloth?".

The code:

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    health = "good"
    def __init__(self, name, age):
        self.name = name
        self.age = age
        def description(self):
            print self.name
            print self.age
            sloth = Animal('George', 3)
            ocelot = Animal('Marley', 5)
            hippo = Animal('Johns', 2)
            hippo.description()
            print hippo.health
            print sloth.health
            print ocelot.health

#2

Hi these lines

            sloth = Animal('George', 3)
            ocelot = Animal('Marley', 5)
            hippo = Animal('Johns', 2)
            hippo.description()
            print hippo.health
            print sloth.health
            print ocelot.health

Doesn't need to be indent


#3

It works. but there's another mistake
Traceback (most recent call last):
File "python", line 14, in
AttributeError: 'Animal' object has no attribute 'description'

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    health = "good"
    def __init__(self, name, age):
        self.name = name
        self.age = age
        def description(self):
            print self.name
            print self.age
hippo = Animal("Hipster", 1)
sloth = Animal('Spot',7)
ocelot = Animal('CAtt',3)
print hippo.description
print hippo.health
print sloth.health
print ocelot.health

#4

this line

print hippo.description

add the () do .description


#5

I solved the problem. Thx everybody!:smiley:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.