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 trialLuke Maschoff
820 PointsShopping List trouble
When Kenneth started to add new code to the shopping list, I nearly understood all of it, but I may have missed something, but it seems like I have the same code as him?
Whenever I start the application, it runs, but when I add my first item, instead of automatically putting it in the first position, it asks me where I want to put it, messing everything up. Here is the section where I think it went wrong.
Whenever I press enter to add it to the end of the list as well, it adds another version of the item. ex: If I add apples, it will ask what place, or press enter to add it to the end of the list, and if I press enter it adds 2 to the list, so it would look like
- Apples
- Apples
def add_to_list(item):
show_list()
if len(shopping_list) >= 1:
position = input("Where should I add {}?\n"
"Press ENTER to add to the end of the list\n"
"> ".format(item))
else:
position = 0
try:
position = abs(int(position))
except ValueError:
position = None
if position is not None:
shopping_list.insert(position-1, item)
else:
shopping_list.append(new_item)
show_list()
Luke Maschoff
820 Pointshttps://w.trhou.se/frtj0snn2y Snapshot of workspace
1 Answer
KRIS NIKOLAISEN
54,971 PointsYou have an extra add_to_list(new_item) at line 85. Remove that and the rest appears to be ok.
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsCan you post a snapshot of your workspace? It is the camera icon in the upper right corner.