Lesson 9, everything is perfectly fine, something still is going wrong


#1

I know u may think that if I write, everything is perfectly OK, u think I am just a stupid guy, problem is I defined everything, the checker still thinks i haven't. Take a look:

(SOMETHING WENT WRONG WITH SELECTING TXT THAT IS CODE, NOT MY FAULT, TRIED TO REPAIR IT
` 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("Hipopus", 6)
sloth = Animal("Lenn", 2)
ocelot = Animal("KitCat", 4)
description(hippo)

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

It replays:
**Oops, try again. Did you create an Animal() called sloth? **
EDIT: After I reloaded the page, it said that in first line there is a problem in
HELP!


#2

Hi your code works fine its could be a indent problem so here your code with the right indent

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("Hipopus", 6)
sloth = Animal("Lenn", 2)
ocelot = Animal("KitCat", 4)
description(hippo)

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

#3

Yeah, it kinda solved the problem, now it just says that "description" function is not defined :confused:


#4

@willmish: The problem is that you're trying to use the function description() but you forgot that's inside your class and you should use an instance to access it.
Doing description(hippo) doesn't really work, you should've done hippo.description().
No need to pass any parameter since your program knows which instance is accessing the method.


#5

Thanks a lot! It solved the problem!


#6

No problem, Willmish! Glad to help!