9. They're Multiplying



My code gives the following error:

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

However, the printed results look exactly as I expected them to:


Am I missing something?

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(aminal):
        print aminal.name
        print aminal.age
    hippo = Animal("Hun", 32)
    sloth = Animal("Bob", 1)
    ocelot = Animal("Babou", 15)
    print hippo.health
    print sloth.health
    print ocelot.health


Indentation,Your code is missing indentation!

also check this line of code..
also when we call a method on some instance we do this..

if X is our instance and Z is its method.



Ok, thanks, that solved the issue. Since I didn't have any problems with my indentation or calling of the description method in the previous lessons, I thought I was on the right track. I suppose those exercises weren't checking for that, only what was being printed?


Hi @jgiglio,
If you look back the previous section then It's pretty sure thing that your indentations are rightly put and methods are called that way.

Indentation in python is key thing,Without it python code does not get any structure.
It separates different blocks of codes.


I understand, but in this specific case, calling description(hippo) indented within the class does indeed print the name and age of the hippo. My point being that even though this was an incorrect method of calling the description method, since it printed correctly, I was able to move on.


I don't know how that program(your first program that you posted ) printed them.
I have copy-pasted your same code and tested it.
This what I got...

and when I fixed the indentation but did not fixed the method calling,This what I had as Output..

I think its just CC interpreter that sometimes does not work well!


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