8/18


#1

I am getting a bit confused over how arguments are passed around with classes and objects. Here is my code, on line 12 (beginning with hippo) I am getting an error message: TypeError: description() takes exactly 3 arguments (1 given)

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    def __init__(self,name,age):
        self.name = name
        self.age = age
    # Add your method here!
    def description(self,name,age):
        print self.name
        print self.age
#Create instance of hippo
hippo = Animal("Henry",10)
#Call description to print name and age
hippo.description()

#2

@scriptpro91844,

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    def __init__(self,name,age):
        self.name = name
        self.age = age
    # Add your method here!
    #def description(self,name,age):
    def description(self):
        print self.name
        print self.age
#Create instance of hippo
hippo = Animal("Henry",10)
print hippo.__dict__
dir(hippo)
#Call description to print name and age
hippo.description()

#3

Thanks for this. I was a bit confused by these lines as these functions haven't been introduced in the course so far.

*print hippo.__dict__*
*dir(hippo)*

However, turns out they are not really necessary (at least from the Codeacademy perspective. All that was needed was to change attributes of the the def description(self): line, also as shown in the picture. After this it worked fine.


#4

@scriptpro91844,

But did you notice,
that the is_alive property is NOT displayed in

print hippo.__dict__

#5

This is mine..hope can help..it works for me

class Animal(object):
    """Makes cute animals."""
    is_alive = True
    def __init__(self, name, age):
        self.name = name
        self.age = age
   
    def description(self):
       print self.name
       print self.age
       
hippo = Animal("Jhon", 5)
hippo.description()