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

Python Shopping List Error: Unbound Local Error for position of new item in list?

Hi all--

I have been following along and checked my code against the instructors and am still stumped.

I can add new items to the list, but the positioning of them throws the error Unbound Local Error: local position referenced before assignment and have not been able to work a solution. (The error references Line 76 and then Line 28.)

Here is the snapshot of my code...

https://w.trhou.se/2ediswhzgu

Can anyone advise?

Agustin Fitipaldi
Agustin Fitipaldi
1,644 Points

well, for starters you might want to spell check you document, the first declaration of position is spelled wrong =)

2 Answers

Chris L
Chris L
8,619 Points

As Agustin said:

if len(shopping_list):
    postion = input....

should be position

Ohmigosh! Thank you both so much for catching that! I feel so silly.

With that said, I do want to use this as a growth opportunity--do you all have any guidance on how to spell check in editors/IDE or suggestions as to which would be best?

(I am trying to learn coding on top of working full time plus, so I have some really tired eyes.)

Also, for future reference should an Unbound Local Error serve as a tip off to a typo? (I am trying to better understand the meaning of error codes so I can trouble-shoot myself faster.)

Thank you both again for the responses!

Agustin Fitipaldi
Agustin Fitipaldi
1,644 Points

not necessarily... the Unbound Local error is a subclass of Name Error, it refers to a local variable that has been referenced but no value has been assigned... so if you remember setting a value for a variable and it says you didn't, probably misspelled it. Generally, whenever you get an error code that you don't understand try and google it and see what it says on the python website. Understanding error codes is a vital part of learning how to debug your code.

Chris L
Chris L
8,619 Points

I personally use Sublime Text 3, and to spot this, I added a package called Compare Side-By-Side and compared it against my version....not sure how helpful that will be for spell-checking in general, though.

Sublime 3

https://packagecontrol.io/packages/Compare%20Side-By-Side