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 trialDavid Mikeska
17,536 PointsHaving issues adding more than one item to the list and having problems exiting application by typing DONE.
# Create a list
shopping_list = []
# Create a function that adds an item to the list.
def add_list(item):
shopping_list.append(item)
#Let user know the item has been added and state the number of items in the list.
print("Added: Item has just been added {}".format(len(shopping_list)))
def show_help():
print("What should we pickup at the store??")
print("""
Enter 'DONE' when you are finished.
Enter 'HELP' when you need help
""")
show_help()
while True:
new_item = input("> ")
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
continue
#Call function that adds item to the list
add_list(new_item)
formatted by staff
1 Answer
Megan Amendola
Treehouse TeacherHi! You need to move the add_list()
call inside of your while loop
while True:
new_item = input("> ")
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
# you don't need this its a loop so it will continue anyways-> continue
else:
#Call function that adds item to the list
add_list(new_item)
David Mikeska
17,536 PointsDavid Mikeska
17,536 PointsAhh. Thanks. Very helpful!