Why does my code print this weird long line?


So I was doing this exercise this afternoon as linked below, and my code outputted ">" instead of "Jacala" and "20" as I've expected. When I changed the code "print Hippo.description" to "Hippo.description", nothing was printed at all. As I just learnt about the class in python, I guess there's something off with my 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):
        print self.name
        print self.age

Hippo = Animal("Jacala", 20)
print Hippo.description


Okay, the description method you are trying to call won't go this way.

rather, you will want to do:

print hippo.name, hippo.age

Also, the language is case sensitive and the instruction says to do hippo not Hippo


Oh, actually I've already passed this exercise and I'm posting only because I'm curious. The instructions implied that the name and age should be printed on separate lines, and "Hippo" worked fine for me.
And thanks for your suggestions! It worked and printed "Jaccala 20". But I still have a question: what's the point of creating the "description" method in the first place if I just have to print the name and age separately? It seems that the "description" method did nothing in relation to the output.


Okay, that' good.

I will suggest this document as a good read: Classes


The method 'description' is a function so you'll need to add parentheses when you call on it.

So print Hippo.description()


yep correct
I found that out pretty soon after I posted this, but still ty! :slight_smile:


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