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 Collections (2016, retired 2019) Lists Shopping List Take Three

Marta P.
Marta P.
2,849 Points

My shopping list is a hot mess

Hey there, so my shopping list doesn't work, and I think I messed it up trying to fix it. Anyone could help me understand what I did wrong?

Thank you! Here is the snapshot: https://w.trhou.se/iyagqkoai6

2 Answers

Hey Marta, looks like you misspelled some things in your add_to_list function on line 53.

def add_to_list(new_item):
    show_list()
    if len(shopping_list):
        position = input("Where should I add {}?\n"
                         "Press ENTER to add to the end of the list\n"
                         "> ".format(new_item))
    else:
        position = 0

    try:
        position = abs(int(position))
    except ValueError:
        position = None
    if position is not None:
        shopping_list.insert(position - 1, new_item)
    else:
        shopping_list.append(new_item)
Marta P.
Marta P.
2,849 Points

Hi! Thank you, I fixed that:) However it keeps giving me the same error...it says "item" is not defined. Although I did exactly as Kenneth did!