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 trialZachary Radcliff
4,276 PointsMy 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)
2 Answers
Steven Parker
231,269 PointsFor 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.
Shanil Mohan R
1,506 Pointsyou 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)
Zachary Radcliff
4,276 PointsZachary Radcliff
4,276 PointsFound it. Indentation error.