10. for your hobbies


#1



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


File "python", line 6
hobbies.append.(hobby)
^
SyntaxError: invalid syntax


hobbies = []

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


#2

Ok, I can see you are still unfamiliar with how variable assignment works here.

When you create a variable then assign a value to it you can override that value if you are not careful.

Your issue is here. When you assign a str value to the variable it then becomes a string. So just rethink how you want to complete the task as currently this is where your issue stems from. Also you cannot append to a string as it lacks that method.


#3

Thanks, it helped me but the real issue was with syntax on this line

hobbies.append.(hobby)

it was supposed to be

hobbies.append(hobby)

#4

On line 6 hobbies.append(hobby) is the correct form. append.(hobby) is wrong.


#5

So, i have this code, which passes to the next exercise, but the last "print" line prints only [0, 1, 2]. How do i make it to print the actual raw_input hobbies ?

hobbies = []

# Add your code below!
for hobby in range(3):
    raw_input('Your hobby: ') # str(raw_input(Your hobby: ')) gives the same result
    hobbies.append(hobby)
print hobbies

Le: i think i see the issue (for hobby in range(3)?), but don't know how to solve.


#6

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