10/19 for your hobbies


#1

hobbies = []

Add your code below!

for hobbies in range(3):
hobbies =raw_input("Your hobbies: ")
hobbies.append(hobby)

gives me the following error:
Traceback (most recent call last):
File "python", line 6, in
AttributeError: 'unicode' object has no attribute 'append'

line 6 : hobbies.append(hobby)

What am I doing wrong? appreciate all the help


#2

Perhaps you want to do this

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

the problem is you were doing this

 hobbies.append(hobby)

but hobby is undefined

and you were getting that weird error because hobbies as you used in these places

for hobbies in range(3):
    hobbies =raw_input("prompt ")

is a string and strings have no append method


#3

thank you very much, the code checked and you manage to explain it clearly


#4

This worked for me:

hobbies = []

# Add your code below!
for hobby in range(3):
    hobby = str(raw_input("please enter"))
    hobbies.append(hobby)

    
print hobbies

#5

I copy pasted the code, and it still doesn't work for me. WTF


#6

What do you mean it doesn't work for you? Are you getting an error like the OP or you are not passing the test?


#7

I got it now. apparently there was a bug, i just refreshed the browser and it worked fine. Thanks mate.


#8

Hey rydan, I tried your code and it works perfectly fine. But then when it prints hobbies it puts a weird 'u' in front of every hobby in hobbies and I don't know where it's coming from. How do I get rid of it or is it supposed to be 'natural'? Thx :slight_smile:


#9

I get the same error!


#10

Same to me. why there is a 'u'?


#11

this is what I did:

hobbies = []

for poo in range(3):
hobbies.append(str(raw_input("Your hobby:")))
print hobbies


#12

I'm wondering the same thing!


#13

Use this code. It works fine

hobbies=[]
for i in range(3):
hobby = raw_input("Enter")
hobbies.append(str(hobby))
i+=1
print hobbies


#14

Why does when this code run, it has a 'u" before each item in the list...

hobbies = []

# Add your code below!
for hobby in range(3):
    hobby = raw_input("Your hobbies: ")
    hobbies.append(hobby)

print hobbies

...but when I add str() before raw_input, the 'u' goes away?


#16

For me a simpler code did the trick.

hobbies = []

for i in range(3):
hobbies.append(raw_input("Input hobby here:"))


#17

The code you wrote is literally the same as what the OP posted except you did not store the user input in a variable and you named your iterator i


#19