10. For your hobbies


I from time to time print the results to see if I screwed up or not.
Even though I passed, the result was . . weird

instead of printing ['food', 'food', 'food'] (since I put food 3 times),

it printed [u'food', u'food', u'food']

What happened? This is my code

hobbies = []

for i in range(3):
hobbies.append(raw_input("What is your hobby?"))

print hobbies


boss the print kinda added a bug. the instruction did not say print em out so remove the print and run the code


i dont know why it prints U...but this work.
hobbies.append(str(raw_input("Write your hobby: ")))


First off, You're right, the str() addition works fine.

Second, this has been discussed in previous threads and as I understand it the `u´ shows up as result of an encoding error from the unicode string.
In this previous thread, people suggest using

hobby.encode ('utf-8')
However, stackoverflow says that this doesn´t work (and it doesn´t) since Python 3 strings are already unicode. This used to work for older versions.


nice info .... helps me understand what the problem was ..


Why is this code wrong>?
hobbies = []
trys_to3 = 0
for trys_to3 <= 3:
hobby = raw_input('what is your favorite hobbys?')
trys_to3 += 1


This is how I made your code work:

hobbies = []
trys_to3 = 0
while trys_to3 < 3:
    hobby = raw_input('what is your favorite hobby?')
    trys_to3 += 1

First, You should indent the last three lines, since they are inside of your loop.

Second, you shouldn't use a for loop, but a while loop. You are running the loop WHILE trys_to3 is less then 3.

Third, You're using trys_to3 <= 3 when you should be using trys_to3 < 3.
<= means "smaller then or equal to"
< means just "smaller then"


Hi just ask why it can not work like this
hobbies = []

Add your code below!

for i in range(3):
hobby = int(raw_input("Your hobby: "))
print hobbies


Your code should look like this instead:

hobbies = []
for i in range(3):
    hobby = str(raw_input("Your hobby: "))
print hobbies

Since you are suppose to type a hobby which is a string, so it should be str and not int,
as str means string while int means integer.