For your hobby


#1
hobbies = []

for i in range(3):
    hobby = raw_input("Hobby?")
    hobbies.append(hobby)

print hobbies

This is the code I ran and I added three 'hobby' to the list 'hobbies', 'reading' , 'writing' and 'gaming'.

Output:
Hobby? reading
Hobby? writing
Hobby? gaming
[u'reading', u'writing', u'gaming']
None

Where did the 'u's come from?


#2

It looks like raw_input() is returning Unicode encoded text, as denoted by the u. I was unable to reproduce this in the lab (Python 2.7.2) using FF.

Hobby? reading
Hobby? writing
Hobby? walking
['reading', 'writing', 'walking']

Please post a link to this exercise so we can test in that interface.

If you want to brute-force your way to normal strings,

... .append(str(hobby))

might do the trick. Just guessing, though, until we see the lesson.


#3

Here is the link

... .append(str(hobby))

Worked, thanks.

I think it might be a bug.


#4

Either way, the lesson passed without the correction. This will also work to produce normal strings:

... .append(hobby.encode("utf-8"))

#6

thanks. that was helpful.


#7

btw are there any courses on c or c++ or c# language?


#8

Not on this site, as yet. It is often requested but there might be a lot involved in presenting that course, not the least of which could be expensive licensing.


#9

Thanks for the information.


#10

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