They're Multiplying!


#1


https://www.codecademy.com/en/courses/python-intermediate-en-WL8e4/1/4?curriculum_id=4f89dab3d788890003000096#

Oops, try again. Did you create an Animal() called sloth?


I expected the code to run the three animals' health status ("good").


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
        
    sloth = Animal ("Terry", 4)
    ocelot = Animal ("Tyler", 3)
    hippo = Animal ("Noreen", 5)
    print sloth.health
    print ocelot.health
    print hippo.health


#2

Could be just the order in which your are querying the attributes.

hippo - sloth - ocelot

Also, my three instances are in that same order.


#3

Try it with a different indentation !!!

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
        
    sloth = Animal ("Terry", 4)
    ocelot = Animal ("Tyler", 3)
    hippo = Animal ("Noreen", 5)
    print sloth.health
    print ocelot.health
    print hippo.health

#4

Thanks so much for your help! Sadly, adjusting indentations didn't seem to fix everything. Now I am receiving the following error message:

Traceback (most recent call last):
File "python", line 1, in
File "python", line 17, in Animal
AttributeError: 'Animal' object has no attribute 'health'


#5

Where did the =indentation= go to....

Try to use indentations in steps of 4 =blanks=


#6

A post was split to a new topic: NameError: name 'Animal' is not defined


#7

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