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 Python Basics (Retired) Putting the "Fun" Back in "Function" Shopping List Redux

Chris Nelson
Chris Nelson
4,603 Points

Shopping List Redux Error: Cannot run function_list.py

Hello, don't understand why I can't run this code. Everything is done correctly I'm pretty sure: Here's the code I've entered:

shopping_list = []

def show_help():
  print("What would you like to pick up at the store?")
  print("Enter DONE to stop adding. Enter HELP for this help. Enter SHOW to see list preview.")

def add_to_list(item):
  shopping_list.append(item)
  print("Added: List has {} items.".format(len(shopping_list))

def show_list():
  print("Here's your list:")
  for item in shopping_list:
    print(item)


show_help()

while True:
  new_item = input("> ")
    if new_item == 'DONE':
      break
    elif new_item == 'HELP':
      show_help()
      continue
    elif new_item == 'SHOW':
      show_list()
      continue 

    add_to_list(new_item)
    continue

 show_list() 

When I run "python function_list.py" in the Console window, I get this error:

python function_list.py
File "function_list.py", line 11
def show_list():
^
SyntaxError: invalid syntax

Doesn't make any sense. The code at that line is fine. I've tried closing my Workpace down and reloading it several times. Always the same error. It's not a big deal, I can just continue with the course, but I'd like to know why it's not working.

Thanks

Hunter G
Hunter G
6,612 Points

you're missing a " ) " at the end of line 10 i believe.

your code should look like this:

print("Added: List has {} items.".format(len(shopping_list)))

2 Answers

Hi Chris

in your function add_to_list your missing a close paranthesis in the print statement.

def add_to_list(item):
  shopping_list.append(item)
  print("Added: List has {} items.".format(len(shopping_list))) # missing closing parenthesis here 

also check your indentation in the while loop.

see my code below

shopping_list=[]

def show_help():
  print("What would you like to pick up at the store?")
  print("Enter DONE to stop adding. Enter HELP for this help. Enter SHOW to see list preview.")


def add_to_list(item):
  shopping_list.append(item)
  print("Added: List has {} items.".format(len(shopping_list)))

def show_list():
  print("Here's your list:")
  for item in shopping_list:
    print(item)


show_help()

while True:
  new_item = input("> ")
  if new_item == 'DONE':
    break
  elif new_item == 'HELP':
    show_help()
    continue
  elif new_item == 'SHOW':
    show_list()
    continue 
  add_to_list(new_item)
  continue

show_list()

hope this helps

Chris Nelson
Chris Nelson
4,603 Points

Oh man! Can't believe I missed that! Thanks guys. This stuff is mind boggling hahah