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
David Smith
10,577 PointsJust wanted to get peoples opinion on my finished shopping_list_2.py app.
# make a list to hold our items
shopping_list = []
# print out instructions on how to use the app
def show_list():
index = 1
print("Here is your list:")
for item in shopping_list:
print("#{} | {}".format(index, item))
index += 1
def show_help():
# show help
print("What should be pick up from the shops? ")
print("""
Enter 'DONE' to stop adding items.
Enter 'SHOW' to view your list.
Enter 'HELP' to view this message again.
Enter 'REMOVE' to view your list before removing an item.
""")
def add_to_list(new_item):
# add new items to our list
shopping_list.append(new_item)
print("Added {}. List now has {} items".format(new_item, len(shopping_list)))
def remove_item():
# remove an item from our list
show_list()
old_item_index = int(input("Please enter a number: "))
old_item = shopping_list[old_item_index -1]
del shopping_list[old_item_index - 1]
print("removed {}. Your list now has {} items".format(old_item, len(shopping_list)))
show_list()
show_help()
def main():
while True:
# ask for new items
new_item = input("..> ")
# quit the app
if new_item == 'DONE':
show_list()
break
elif new_item == 'REMOVE':
remove_item()
continue
elif new_item == 'HELP':
show_help()
continue
elif new_item == 'SHOW':
show_list()
continue
add_to_list(new_item)
# print out the list
main()