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
Mohamed THIAM
1,091 PointsCan figure out why does my list repeats itself according to the number of items?
shopping_list = list()
print("What should we buy today?")
print("Enter 'DONE' to stop adding items")
while True:
new_item = input("> ")
if new_item == "DONE":
break
print("Added: List has {} items.".format(len(shopping_list)))
continue
shopping_list.append(new_item)
print("Here is you list:")
for item in shopping_list:
print (",".join(shopping_list))
2 Answers
White Moses
3,589 PointsHi! Because this statement - print (",".join(shopping_list)) prints all list devided by comas and it repeats as much as quantity of items in list. But you might need print only items, just change you print to 'print(item)'
Chris Freeman
Treehouse Moderator 68,468 PointsLooking at the last for loop statement:
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> shopping_list = ['apple', 'banana', 'grape']
>>> for item in shopping_list:
... print (",".join(shopping_list))
...
apple,banana,grape
apple,banana,grape
apple,banana,grape
>>>
For each item in the shopping_list, the print statement is being executed.
You do not need the for loop. Simply removed the for loop and unindent the print statement.