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 trialTrent Burkenpas
22,388 PointsHave some issues printing my shopping_list. After I type in DONE my list does not want to show up!
Here is my code
shopping_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)
Thank You
nvcxnvkldsjaklfds
Courses Plus Student 5,041 PointsKenneth Love Your point is right. But, he mentioned he has only issues with printing shopping list. That does mean Issue should be after while termination.
Kenneth Love
Treehouse Guest TeacherKarthikeyan Palaniswamy His break
comes before anything gets added to the list, which would result in a blank list being printed, which would be why the list doesn't show up.
1 Answer
nvcxnvkldsjaklfds
Courses Plus Student 5,041 PointsYour program works great. I do not find any mistakes in there. I would recommend you to check indentation properly. In Python Indentation does matter a lot. You may know Python is a indentation language.
Please use the code below. I did intend them well in my text editor.
shopping_list = []
print("What should we pick up at the store?")
print("Enter 'DONE' to stop adding items")
while True:
new_item = raw_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)
I hope It helps
Trent Burkenpas
22,388 Pointsoh I see. The indentation issue. Thanks!
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherYou have a
break
that's followed by equally-indented lines. Those lines will never be run because they belong to the block that thebreak
is in and thebreak
kicks everything back out to the code after thewhile
loop.