9. They're Multiplying!


#1


https://www.codecademy.com/NrSghtdGrmln26/codebits/U0YnPS/edit

apparently description isn't defined


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("Jane", 8)
sloth = Animal("Sid", 4)
ocelot = Animal("Cat", 6)
    
print hippo.health
print sloth.health
print ocelot.health
description(Hippo)


#2

The above treats description as a global function that takes an object, rather than an object with an instance method.

hippo.description()

#3

Figured it out

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("Jane", 8)
sloth = Animal("Sid", 4)
ocelot = Animal("Cat", 6)

print hippo.health
print sloth.health
print ocelot.health
description(Hippo)


#4

For a pass, maybe, but otherwise, no. description is a method, not a function. It should not take any arguments as it draws on the context object for data.


#5

No, the example was define description, which I did


#6

I copy and pasted this from the example:
def description(self):
print self.name
print self.age


#7

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