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 (2015) Shopping List App Second Shopping List App

How would I create an ordered list from the user input?

How would I create an ordered list from the user input? Instead of "> ", I'd like to have "1.", "2." "3.", etc.

2 Answers

def show_list():
    for item in shopping_list:
        print(shopping_list.index(item) +1, end=" ")
        print(" ",item)

This will add the index number of each item, adding 1 to the index position (so the list number starts at 1 instead of 0). The The "end" piece and space before printing the item is to make the item show up on the same line as the numbers a few spaces away.

Seth Egger
Seth Egger
Courses Plus Student 1,113 Points

shopping_list =[] print("Add something to the cart or type 'DONE' to quit.") count = 1 while True: item = str(input(str(count) + ".")) if item == "DONE": print(shopping_list) exit() elif item == "SHOW": print(shopping_list) continue elif item == "HELP": print("Type DONE to quit, SHOW to see your list, or add more items to your list.") continue else: shopping_list.append(item) count += 1