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

the words 'DONE', 'HELP', and 'SHOW' keeps getting added into my list.

not sure what im doing wrong.

2 Answers

Steven Parker
Steven Parker
231,271 Points

You'd need to show your code to make a more specific answer possible, but it sounds like you are saving the input in the list and then testing to see if it is a special command word.

To keep those words out of the list, your code must test before adding the input to the list.

I ran into that as well. It seems as though the 'new_item' is added to the list whether or not it is printing additional info (e.g. SHOW, HELP). I'm new to python so this may not be the best approach but.......

shopping_list.remove("HELP") shopping_list.remove("SHOW")

seemed to work. Initially, it was creating errors because sometimes "HELP" and "SHOW" were not in the list yet so I ended up using try/pass. This removed the commands from the list leaving just my fruits and vegetables.

shopping_list.append(new_item)  

try:
    shopping_list.remove("HELP")
except:
    pass
try:
    shopping_list.remove("SHOW")
except:
    pass

The next part when the functions are built (shopping_list2) this is no longer necessary. This is my first time through this so I'm sure there's a better way.

Steven Parker
Steven Parker
231,271 Points

It's easier to just do the test first so those words are never added to the list.