Why does my code print this weird long line?


#1



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?

https://www.codecademy.com/en/courses/python-intermediate-en-WL8e4/1/3?curriculum_id=4f89dab3d788890003000096


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


#2

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


#3

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.


#4

Okay, that' good.

I will suggest this document as a good read: Classes


#5

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

So print Hippo.description()


#6

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


#7

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