Bummer! You have been redirected as the page you requested could not be found.

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 (2015) Shopping List App Second Shopping List App

Sean Flanagan
Sean Flanagan
33,235 Points

Unable to work this out

Hi.

I can't figure this out.

How about:

# make a list to hold on to items
shopping_list = []

# print out instructions on how to use the app
print("What do you need?")
print("Enter 'DONE' to stop adding items")

while True:
    # ask for new items
    new_item = input("> ")

    # be able to quit app
    if new_item == 'DONE':
        break

    if new_item == "SHOW":
        print("Here's your list so far")
        print(shopping_list)

    if new_item == "HELP":
        print("Type 'SHOW' to see your list so far.")
        print("Type 'HELP' for help.")
        print("Type 'DONE' when you have finished.")

    # add new items to list
    shopping_list.append(new_item)

# print list
print("Here's your list: ")

for item in shopping_list:
    print(item)

I used SHOW and HELP but when I typed DONE, these appeared on the list as items themselves. Am I supposed to find a way to exclude SHOW and HELP from my list?

Cheers

Sean

1 Answer

You are appending the item onto the list regardless of the command issued. You need to make an else clause like this:

# make a list to hold on to items
shopping_list = []

# print out instructions on how to use the app
print("What do you need?")
print("Enter 'DONE' to stop adding items")

while True:
    # ask for new items
    new_item = input("> ")

    # be able to quit app
    if new_item == 'DONE':
        break

    elif new_item == "SHOW":
        print("Here's your list so far")
        print(shopping_list)

    elif new_item == "HELP":
        print("Type 'SHOW' to see your list so far.")
        print("Type 'HELP' for help.")
        print("Type 'DONE' when you have finished.")

    # add new items to list
    else:
        shopping_list.append(new_item)

# print list
print("Here's your list: ")

for item in shopping_list:
    print(item)
Sean Flanagan
Sean Flanagan
33,235 Points

Hi there.

Just to let you know that your suggestion worked a treat. I've awarded you Best Answer.

Thank you.

Sean :-)

Thanks :)