9. They're Multiplying


#1



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


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:

Hun
32
good
good
good
None

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)
    description(hippo)
    print hippo.health
    print sloth.health
    print ocelot.health


#2

Indentation,Your code is missing indentation!

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

if X is our instance and Z is its method.

X.Z(arguments)


#3

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?


#4

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.


#5

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.


#6

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!


#7

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