The hobby loop?


#1

I know this should be simple but...

ok, so I am getting a syntax error, but not really sure why. I was able to get the script to run and ask the hobby question once, but not three times. so I coded to increment i so that it would ask three times but now i get a this error:

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

here is the code

hobbies = []

# Add your code below!
for i in range(3):
    hobby = (raw_input('What is one of your hobbies:')
    hobbies.append(hobby) 
    i += 1:
print 'You like to %s' % hobbies

#2

The variable increments automatically in a for loop like that, so you don't need to increment it manually. Besides, that colon after you increment is a syntax error in itself.

Also, the bracket before the raw_input should be there. Python may be expecting something else as there's not even a closing bracket, which may cause the error. Remove that first bracket.


#3

thank you...very well explained and understood :slight_smile:


#4

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