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 Shopping List Introduction

Moises Miguel
Moises Miguel
5,028 Points

Im using sublime text and when i try to write something in my list i get a error message in my terminal.

It says that what ever i type in is "not defined". How do i solve this?

shopping_list = []

print("What should we pick up at the store ?") print("Enter 'DONE' to stop adding steps ")

while True: new_item = input("> ")

if new_item == "DONE": break

shopping_list.append(new_item)

print("Here is your list: ")

for item in shopping_list: print(item)

1 Answer

try typing this into the Terminal:

python -v

What result does it print out when you type this?

Moises Miguel
Moises Miguel
5,028 Points

a lot of words and than the 3 greater than symbols. so it takes me to the python shell?

Oh never mind. I thought that would show you the version of Python.

can you try typing python --version into the shell?

EDIT: And also tell me what you get back?

And what's the command you use to run your file?

Moises Miguel
Moises Miguel
5,028 Points

python shopping_list.py

aha! You are using Python 2, which sometimes causes errors with your Python 3 code. In Python 2, you cant just type in "Hello!" into an input field. If you do so, Python 2 will start to look for a variable named like that. So, there's a couple ways to fix that. You could use the raw_input() function instead of input(), or, you can install python3 then type in this instead into the Terminal:

python3 shopping_list.py

Hope this helps and good luck coding! ~Alex

Also, you might find this course helpful for these things.

Moises Miguel
Moises Miguel
5,028 Points

Thanks a lot alex, everything is working just fine now!

No problem!