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 Introducing Lists Build an Application Display the List

Carlos Marin
Carlos Marin
8,009 Points

Invalid syntax

There is a syntax error but everything looks fine to me?

File "shopping_list.py", line 22                                                                    
    show_help()                                                                                       
            ^                                                                                         
SyntaxError: invalid syntax  
shopping_list = []

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

def add_to_list(item):
    shopping_list.append(item)
    print("{} was added to your shopping list.\nYou have {} items in your cart".format(item, len(shopping_list)))


# Define a fuinction named show_list that prints out all the items in the list
def show_list():
    print("Shopping Cart:\n")
    for item in shopping_list:
        print("Item: {}".format(item)


show_help()       
while True:
    new_item = input("> ")
    if new_item == "DONE":
        break
    elif new_item == 'HELP':
        show_help()
        continue  
    add_to_list(new_item)
Dave StSomeWhere
Dave StSomeWhere
19,870 Points

It is common for the error message to point to the line after the problem, especially when something is missing - it doesn't know about the issue until you try to start the next command and the interpreter is still trying to finish the last command.

Your syntax issue is on the preceding line, and something is missing...

Carlos Marin
Carlos Marin
8,009 Points

Hey Dave, If you want the "best answer" bonus, I need you to reply as an answer.

1 Answer

Carlos Marin
Carlos Marin
8,009 Points

Awesome! Thank you, Dave!