Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Lists Redux Shopping List Take Three

Srikanth Srinivas
Srikanth Srinivas
1,465 Points

This sort of shopping list would still do the same things as yours when i compile it?

shopping_list = []

print("This is a shopping list.")
itemtoadd = input("Enter an item you wish to add, or type DONE to exit.")

while itemtoadd != "DONE":

    index = int(input("What number would you like to place this item in your list?"))
    print("You have entered {}. Your list now contains {} items.".format(itemtoadd,(len(shopping_list))))
    itemtoadd = input("Enter an item you wish to add, or type DONE to exit.")

if itemtoadd == "DONE":
    print("Your list now contains the following items: {}".format(",".join(shopping_list)))

I wrote this on an online compiler and it seems to work the same way yours does, but with reduced lines of code. Am I missing something? Thanks!

1 Answer

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

It'll accomplish the same goals, more or less, but doesn't take into account the fact that people might enter non-ints when you ask for an index or might not want to put the new item somewhere special.

You don't need that last if, either. Once the while loop ends, the "DONE" is implied and that code should run.

Good job coming up with another solution!