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 Display the List

syntax error .My Enter "SHOW" to see current list , is giving a syntax error, not sure why

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 hel""") Enter "SHOW" to see your current list. """)

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

define a new function named show_list that prints all the items in the 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

#Enable the SHOW command to show the list.Don't forget to update your HELP documentation
#Hint:make sure to run it
elif:
    new_item == 'SHOW':
        show_list()
        continue

add_to_list(new_item)   

show_list()

2 Answers

Steven Parker
Steven Parker
220,415 Points

By itself "elif:" is not a valid statement. There needs to be a conditional expression between "elif" and the colon, and it looks like the next line has that. So those two lines should be combined into one.

But Python is extremely hard to read without proper formatting. In future questions, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

Chandelor Simon
Chandelor Simon
2,242 Points

^ What he said. In this case the computer's "thinking", "elif _____:... elif what, man?" Now I THINK I know what you were thinking here, because for things like 'else' and 'try' - you DO put the ':' after.

For example, in the check_please.py program we made earlier in Python Basics, we tell the computer to 'try: ' the things that follow, 'except ValueError as err:' if something goes wrong and do what follows there (print some user-friendly messages); otherwise (else:), tell them how much everyone owes.

If you think about it like a conversation I think it helps. This example below won't be proper code or anything, but I think it'll help illustrate my point:

(Here's what I want you to) try: this stuff I'm writing here. and this. and this, too. (It's almost like 'try' is setting up a list)

elif this stuff I'm writing here is the case: do this. and this. and this, too.

else: do this instead.

Imagine the ":" and new lines as a break or pause in the conversation - like ellipses. You wouldn't say, "if....this stuff i'm writing here is the case...". You'd say, "If this stuff I'm writing here is the case..."