10/19 Make sure you get 3 hobbies from user


#1

So I've looked at the forums already to see where i was going wrong but my code is near identical to what I've seen and i have no idea what I'm doing wrong.

for hobby in range(3):
    hobby = raw_input("Tell me your hobbies.")

hobbies.append(hobby)
print hobbies

#2

Your loop has to append not overwrite the variable.

EXAMPLE:

a = 1
for i in range(3):
    a = i
print(a)
# OUTPUT: 2

# VS

a = [1]
for i in range(3):
    a.append(i)
print(*a)

# OUTPUT: 1 0 1 2

#3

@microblaster93274 I am having the exact same issue. I have tried using different variations of code others users say worked, but end up getting this.

I am guessing something changed with this page because this code worked in this youtube clip @ 10:49 https://www.youtube.com/watch?v=0Z9hB5_KQKk&index=14&list=PLHdCowjFIBmI1UV60W1TVa7l91Psnw73E

I have also tried changing the range values in case anyone was wondering.


#4

@thestarsof2050 It looks to me like its because you haven't put anything between the brackets after raw_input. That's what the error is saying, but that's really strange, because I tried deleting that on my one and it still worked perfectly, it just didn't as the question...

try:
hobby = raw_input("What is your hobby?")


#5

Thank you @zeziba!
I wouldn't have thought of that. I had been overwriting the variable all along too. :slightly_smiling:


#6

In the end, this is the code that I typed, and it worked perfectly.

hobbies = []

for hobby in range(3):
    hobby = raw_input("What's your hobby?")
    hobbies.append(hobby)
print hobbies

#7

Why, when I do this, does my new list hobbies look like this in the output box?:
[u'sledding', u'skiing', u'snowboarding']. I don't know where these mysterious 'u's are coming from.


#8

I also not understand why it shows 'u's


#9

I also get these u' s in front of my input string. But somehow only when I print the whole list, not when I access a certain index. Does someone know why


#10

Thanks man!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


#11

I also got this "u" problem,is it related to my code?


#12

same as well. sorry to have to revive this old thread, but anyone mind sharing why?