10/19 For your hobbies - Error


#1

Can someone help me with this error, I’m really not seeing where the problem is. I think I have the identation right in the loop (two spaces) on both lines. Thank you!

My code:

hobbies = []

for hobby in range(3):
  hobby=str(raw_input("Name your hobby: "))
  hobbies.append(hobby)

print hobbies

The Error:
File “python”, line 6
hobbies.append(hobby)
^
IndentationError: unindent does not match any outer indentation level


#2

Try this:

hobbies = []

for hobby in range(3):
    hobby = str(raw_input("Name your hobby: "))
    hobbies.append(hobby)

print hobbies

#3

It may be a good idea to change your variable “hobby” in the for loop. It seems to me that you are using the same variable twice; once to count through the iterations of the loop and another to store your raw_input.

Alternatively just use hobbies.append(raw_input("Name your hobby: ")) and kill two birds with one stone.


#4

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