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

My function isn't displaying when I run my code. It isn't showing me the number of items, or how many items. Any ideas?

shopping_list = []

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

def show_help(): print("What should we pick up at the store?") print(""" Enter 'DONE' when you are finished entering items. Enter 'HELP' for help with this application. """)

show_help() while True: new_item = input("> ")

if new_item == 'DONE':
    break
elif new_item == 'HELP':
    show_help()
    continue
    add_to_list(new_item)

Found it. Indentation error.

2 Answers

Shanil Mohan R
Shanil Mohan R
1,494 Points

you have added the function call add_to_list(new_item) in the elif block which will get executed only if you type HELP. Since you have a continue statement right after the function call show_help() program the will go back to executing the while statement again without ever executing the function add_to_list(). You should therefore write your code like this:

if new_item == 'DONE': break elif new_item == 'HELP': show_help() continue add_to_list(new_item)

Steven Parker
Steven Parker
215,987 Points

For the benefit of other readers, the line after "continue" (that calls "add_to_list") should not be indented as far.

Also, when posting code, use Markdown formatting to preserve the code appearance (particularly indentation).

And an even better alternative to posting code is to make a snapshot of your workspace and post the link to it here.