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 trial

Python

Geovany Martinez
Geovany Martinez
7,727 Points

shopping_list2

May someone help me figure out why the code is not working? It gives me the following error on line 26 (while True:) :

File "shoppingLis.py", line 26 while True: ^ SytaxError: invalid syntax

I'm trying to figure out why I'm getting this error.

shoppingList = []

def show_help():
  # print out instructions on how to use the app
  print ("What should we pick up at the store?")
  print ("Enter 'DONE' to stop adding itmes.")
  print ("Enter 'SHOW' to see the current list.")
  print ("Enter 'HELP' to get help.")

show_help()  

def show_list():
  # print out the list
  print("Here's your list: ")

  for item in shoppingList:
    print(item)

show_list()    

def add_to_list(newItem):
  # add new items to our list
  shoppingList.append(newItem)
  print("Added {}. List now has {}.".format(newItem, len(shoppingList))

while True:
  # ask for new items
  newItem = input("> ")

  # be able to quit the app
  if newItem == 'DONE':
    break
  elif newItem == 'HELP':
    show_help()
    continue
  elif newItem == 'SHOW':
    show_list()
    continue
  add_to_list(newItem)

Moderator edited: Markdown added so that code renders properly in the forums. -jn

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Geovany! You're doing great, and these compiler errors can be tricky to interpret sometimes when you're first starting. So I'm going to give you a hint that will hopefully help you save a bunch of time:

:bulb: When you see something like this and it says the error is on line 19 (for example), but you cannot find anything at all wrong with line 19, start looking upwards in your code. Nine times out of ten the problem is on the line immediately before that.

This is the case here. The line immediately before your while True: is missing a closing parenthesis at the end. You have three open parentheses in that line, but only two closing parentheses. Adding a closing parenthesis to the line above causes the code to compile and run.

Hope this helps! :sparkles:

Geovany Martinez
Geovany Martinez
7,727 Points

Jennifer,

Thank you so much. I can't believe I missed that. Reasons why breaks are needed haha.