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) Shopping List Shopping List Project

Tracy Mull
Tracy Mull
1,768 Points

shopping_list.py does not run correctly. "Added..." message does not print nor does the list get printed at the end.

I've double checked my code with the videos, yet some steps are not executing correctly in my workspace. I'm not receiving an error either.

Can anyone help me out? Am I missing something?

What I see in my console:

<p> treehouse:~/workspace$ python shopping_list.py

What should we pick up at the store?

Enter 'DONE' to stop adding items.

Apples

DONE

Here's your list:

treehouse:~/workspace$ </p>

4 Answers

Hi Tracy you almost had it spot on apart from missing an else statement and some indentation. I have amended your a code a bit see below.

shopping_list = list()

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

while True:
  new_item = input("> ")

  if new_item == 'DONE':
    break
  else:
    shopping_list.append(new_item)
    print("Added! List has {} items".format(len(shopping_list)))
  continue

print("Here's your list:")

for item in shopping_list:
  print(item)

hope this helps

Tracy Mull
Tracy Mull
1,768 Points

Hooray! That did the trick. Thank you!

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

Looks like you are not in a while loop. If you are trying to exit on DONE and print the list. Than the DONE function needs to print the list. The list must also be at the proper scope. Or if you are not in a while loop try something like this.

A = True

while A:

all your code

When you type DONE - the list will print. But you need to have a way to EXIT the loop. So how about, type DONE to see your list, and EXIT to exit the program. Then in the EXIT function. Put A = false.

This way the while loop will end.

It's hard without seeing your code. If you post the code, I can help you more.

Tracy Mull
Tracy Mull
1,768 Points

Thanks. Here is my code so far:

''' <p> shopping_list = list()

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

while True:
  new_item = input("> ")

  if new_item == 'DONE':
  break

 shopping_list.append(new_item)
 print("Added! List has {} items".format(len(shopping_list)))
 continue

print("Here's your list:")

for item in shopping_list:
  print(item)

<\p>

'''

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

A little less code, I changed the DONE to make new item always upper in the event I actually typed done and note DONE. Put it into a while loop for break and continue are not needed.

shopping_list = list() 
print("What should we pick up at the store?\n Enter 'DONE' to stop adding items.")
Run = True
while Run:
    new_item = raw_input("Item to add> ") 
    if new_item.upper() == 'DONE':
        print("List has {} items.\n Here is your list {}".format(len(shopping_list), shopping_list))
        Run = False
    shopping_list.append(new_item)
    print("Added! List has {} items and here they are {}".format(len(shopping_list), shopping_list))