For your hobbies


#1

Below this line, add a link to the EXACT exercise that you are stuck at.

https://www.codecademy.com/en/courses/python-beginner-en-cxMGf/1/2?curriculum_id=4f89dab3d788890003000096

In what way does your code behave incorrectly? Include ALL error messages.

My code works and passes however, to see if my code worked properly I printed it and it doesn't work that great.


hobbies = []

# Add your code below!
for i in range(3):
    raw_input("What is one of your hobbies?")
    hobbies.append(raw_input)
    
print "Your hobbies are %s" % hobbies

It prints

What is one of your hobbies? eating
What is one of your hobbies? sleeping
What is one of your hobbies? drinking
Your hobbies are built-in function raw_input>, , <built-in function raw_input
None

Why doesn't it print what I want it to


#2

You're appending a function to your list. raw_input is a function. [].append(raw_input) will therefore add that function to the list. Reconsider the behaviour of raw_input and what you can do to leverage that


#3

Silly me, got ya!

new code still funny though

hobbies = []

# Add your code below!
for i in range(3):
    hobbie = raw_input("What is one of your hobbies?")
    hobbies.append(hobbie)
    
print "Your hobbies are %s" % hobbies

What is one of your hobbies? eating
What is one of your hobbies? sleeping
What is one of your hobbies? drinking
Your hobbies are [u'eating', u'sleeping', u'drinking']
None

now prints a 'u' before my hobbies, what gives?


#4

It's also printing quotes, commas, spaces and brackets, more or less the same thing. Why are the u's what's strange? You could create a string and format it to your fancy.


#5

Because I understand why the other things are there, whats the u about?


#6

never mind, doing it like this

print "Your hobbies are %s" % " ,".join(hobbies)

#7

The u is there to say that they are unicode strings, as opposed to the default string type. In python3 unicode is the default string type


#8

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