Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTristan Gaebler
6,204 PointsI'm getting a syntax error that I can't figure out
Here's my code
shopping_list = list()
print("What should we pick up at the store?")
print("Enter 'Done' to stop adding items")
while True:
new_item = input(">")
if new_item == 'Done':
break
shopping_list.append(new_item)
print("Added! List has {} items.".format(len(shopping_list))
continue
print("Here's your list:")
for item in shopping_list:
print(item)
It says continue is the probelm
3 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsAre you running with Python 3?
In python 2, input([prompt]) is equivalent to **eval(raw_input(prompt))
So python2 is trying to evaluate your input. In **this** case, your input needs to be as strings: ```"Apples"``` or ```"Done"```. (See [docs](https://docs.python.org/2/library/functions.html#input))
If you run your code with python 3, it should work as expected!
In python 3, **input([prompt])** reads a line from input, converts it to a string (stripping a trailing newline), and returns that. (See [docs](https://docs.python.org/3/library/functions.html#input))
Chris Freeman
Treehouse Moderator 68,441 PointsSometimes the error is in the line just above where the error is indicated due to "runaway" syntax like a missing quote (") or a paren ")". In your case, you need another paren to close the print function:
print("Added! List has {} items.".format(len(shopping_list))) # <-- added paren
Tristan Gaebler
6,204 PointsOkay that fixed it, but now I'm getting a new error. Every time I input something it gives me an error. This is what it says
Traceback (most recent call last): File "shopping_list.py", line 8, in <module> new_item = input(">") File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
Dalton DeMaria
5,679 PointsYou don't need the continue at the end of the while block. It is redundant, as a while loop will run the code within the block as long as the condition is true and break/return isn't used to escape. I'm not sure if that would make python freak out, though.
Here is my version of your code that works for me:
shopping_list = list()
print("What should we pick up at the store?")
print("Enter 'Done' to stop adding items")
while True:
new_item = input(">")
if new_item == 'Done':
break
shopping_list.append(new_item)
print("Added! List has {} items.".format(len(shopping_list))) #added paren (chris' answer)
#removed continue at this line
print("Here's your list:")
for item in shopping_list:
print(item)
Tristan Gaebler
6,204 PointsTristan Gaebler
6,204 PointsYa I was running python 2. Thanks for the help!!