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

Shopping list app in python.

This is all my code, I have followed the tutorial, this i s just the first part, not the second. Could you please tell me what's wrong? Thanks

make a list to hold to new items

shopping_list = []

instructions on how to use the app

print("What should we buy from the shops")

print("Enter 'DONE' to stop adding items")

while True:

#asks for new items

new_item = input("> ")

#be able to quit the app
if new_item == 'DONE':
    break
#add items to shopping list
shopping_list.append(new_item)

tells you your list

print("Here's your list:")

prints out the items

for item in shopping_list: print(item)

'''

make a list to hold to new items

shopping_list = []

instructions on how to use the app

print("What should we buy from the shops") print("Enter 'DONE' to stop adding items")

while True: #asks for new items new_item = input("> ")

#be able to quit the app
if new_item == 'DONE':
    break
#add items to shopping list
shopping_list.append(new_item)

tells you your list

print("Here's your list:")

prints out the items

for item in shopping_list: print(item) '''

'''python

make a list to hold to new items

shopping_list = []

instructions on how to use the app

print("What should we buy from the shops") print("Enter 'DONE' to stop adding items")

while True: #asks for new items new_item = input("> ")

#be able to quit the app
if new_item == 'DONE':
    break
#add items to shopping list
shopping_list.append(new_item)

tells you your list

print("Here's your list:")

prints out the items

for item in shopping_list: print(item) '''

1 Answer

Hi Augustine,

It would be really helpful if you provided the error that you are getting. The syntax of your code looks fine so it is likely an indentation issue and we would need to see it properly formatted in order to troubleshoot.

But here is a properly indented version based on the code you provided and it seems to work fine for me. Again, I'm not exactly sure what error you are getting or if you aren't getting an error at all but the code isn't doing what you want it to.

shopping_list = []

print("What should we buy from the shops")
print("Enter 'DONE' to stop adding items")

while True:
    #asks for new items
    new_item = input("> ")

    #be able to quit the app
    if new_item == 'DONE':
        break

    #add items to shopping list
    shopping_list.append(new_item)

print("Here's your list:")

for item in shopping_list:
    print(item)

Thanks, but the problem is that i do not see the list after i type 'DONE', that is supposed to happen. Eg. cat dog chicken DONE and then it doesn't show the list of dog, cat, chicken

Would you be able to re-format your code on your original post so we can troubleshoot it?

How do i do that?

Enclose your code in 3 backticks (```), above and below everything that you want to be formatted. Note that these are not quotes. The backtick is usually found in the upper left corner of your keyboard, sharing the same key as the ~ symbol. After the first set of backticks, you can add the name of the programming language for extra syntax formatting.

Just copy and paste your code exactly as you have it in the challenge and it'll automatically set the spacing for you.

Example:

```python

name = "Treehouse"

```

Will produce:

name = "Treehouse"

You can see the the Markdown Cheatsheet for more formatting options.

#make a list to hold to new items
shopping_list = []


#instructions on how to use the app    
print("What should we buy from the shops")
print("Enter 'DONE' to stop adding items")

while True:
    #asks for new items
    new_item = input("> ")

    #be able to quit the app
    if new_item == 'DONE':
        break
    #add items to shopping list
    shopping_list.append(new_item)

#tells you your list
print("Here's your list:")

#prints out the items
for item in shopping_list:
    print(item)

That is very strange. Your code works perfectly for me.

Are you sure you are entering the word DONE correctly? It should be in all capitals, with no quotes.

And are you making sure to enter each word separately? In an earlier comment you said:

Thanks, but the problem is that i do not see the list after i type 'DONE', that is supposed to happen. Eg. cat dog chicken DONE and then it doesn't show the list of dog, cat, chicken

Are you entering all the words in one input? Because then it won't work like you are expecting. Each item needs to be entered in separately. Otherwise everything you enter on one line will be treated as one item.

This is what your program should look like when you run it.

What should we buy from the shops
Enter 'DONE' to stop adding items
> cat
> dog
> chicken
> DONE
Here's your list:
cat
dog
chicken