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 (Retired) Putting the "Fun" Back in "Function" Shopping List Redux

Code follows the video, yet I still get errors.

I've typed the code along with Kenneth in the video, yet for some reason I can't get the code to run correctly.

Here's my code: shoping_list = []

def show_help(): print("what should we pick up at the store?") print("Enter DONE to stop.")

def add_to_list(item): shopping_list.append(item) print("Added! List had [] items.".format(len(shopping_list)))

def show_list(): print("Here's your list:") for item in shopping_list: print(item)

show_help()

while True: new_item = input("> ") if new_item == "DONE": show_list() break add_to_list(new_item) continue

show_list()

and the output error I get is this:

DONE
Here's your list:
Traceback (most recent call last):
File "shopping_list.py", line 23, in <module>
show_list()
File "shopping_list.py", line 15, in show_list
for item in shopping_list:
NameError: name 'shopping_list' is not defined

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Henry,

White space is important in Python, so it would be helpful if you wrapped your code in tags like this:

```Python

[All your code]

```

If you do this, your code will be formatted appropriately!

Greg Kaleka
Greg Kaleka
39,021 Points

For the record, I meant here in the forum. Lol - don't do this in your actual code!

2 Answers

Henrik Hansen
Henrik Hansen
23,176 Points

It looks like you misspelled shopping list in the first row. But i don't know any python, so it is hard for me to read ^_^

I think my issues were a combination of both those things:

I cleaned up the white space and checked a couple indents, and corrected my spelling error in the beginning. The code is now running like butter.

Greg, I'm glad you clarified that. I had some really confusing moments with that. Ha.