Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Lists Build an Application Add Items

795 Points

Syntax error for no clear reason

I'm having a syntax error and I can't understand why:

shopping_list = []

def add_to_list(item):

def show_help():
    print("What should we pick up at the store")
Enter 'DONE' to stop adding items.
Enter 'HELP' for this help.

while True:
    new_item = input("> ")

    if new_item.upper() == 'DONE':
    elif new_item.upper() == 'HELP':

treehouse:~/workspace$ python shopping_list.py                                                                                           
  File "shopping_list.py", line 8                                                                                                        
    def show_help:                                                                                                                       
SyntaxError: invalid syntax

2 Answers

Michael Hulet
Michael Hulet
47,842 Points

Make sure you've saved your file here before running it, because the traceback that Python is complaining about looks different from what's in your file. The traceback shows show_help being declared like this:

def show_help: # Note the lack of parentheses here

However, in the code you have above it, show_help appears to be declared properly, with parentheses, and there should be no syntax error there. This suggests to me that you simply forgot to save your file after fixing it, which is a very easy thing to forget in Workspaces 🙂

I've saved my file and reloaded the workspace, and I too am getting this error.

You need to add two )) after the """ in the show_help function.

I had the same problem, the error message is quiet misleading