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 programming/ this code doesnt run when i tried. please help

shopping_list =list()

print("what we pick up at the store?")
print("Enter DONE to stop adding item.")

while true:
   new_item=input(">")

if new_item == 'DONE':
  break

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

print("He's your list:")

for item in shopping_list:
  print(item)

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You only have one line inside your while loop. Also, you used true, a variable that doesn't exist, instead of True, the Python boolean. If you had used True, your while loop only has one statement in it and that statement doesn't ever break the loop, so it'll run forever without doing anything but looping repeatedly.

Ricky Catron
Ricky Catron
13,023 Points

I think what you need to do is simply indent your work

shopping_list =list()

print("what we pick up at the store?")
print("Enter DONE to stop adding item.")

while True:
   new_item=input(">")

   if new_item == 'DONE':
     break

   shopping_list.append(new_item)

   print("Added! list has {} item.".format(len(shopping_list)))
   continue

print("He's your list:")

for item in shopping_list:
  print(item)

What this does is A. The loop will not run forever anymore. If the user enters DONE it will break. B. It will now add the the input to the list when you enter it.

Hope I helpped!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

The print("Added!... line and the continue after it (even though it's effectively unneeded) should be indented too.

Ricky Catron
Ricky Catron
13,023 Points

Whoops thank you! I have edited it with your advice.