A methodological approah


#1

Purely for my own self interest, I removed print in "print self.name" and "print self.age" and replaced it with "return". It gave me the name and not the age as in
Bigly
True
None
with a codecademy error " Oops, try again. Animal('Hathi', 14).description() doesn't print anything!" which is not quite correct because it printed name. Please ignore the last line of the code. Thank you


Replace this line with your code. 
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):
        return self.name
        return self.age
hippo = Animal("Bigly", 6)
print hippo.description()
print hippo.is_alive


#2

what exactly is your question? I mean, i understand what you are doing, but see no question


#3

Oops sorry.The question is why does it not work with return self.age but works with print self..name and print self age and return.self name but not with return self.age


#4

this depends on your definition of works, there are two things:

valid syntax
what the exercise wants you to code

the exercise wants you to use print explicitly in the description method

also, realize that functions and methods end when a return keyword is reached, so description method currently only return the name


#5

Thank you.I thought I go outside the boundary a little


#6

sometimes that is possible, this time it was not


#7

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