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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ceil-Ian Maralit](https://uploads.teamtreehouse.com/production/profile-photos/10173842/micro_28459F92-CD3A-407B-BF11-B95FB66D7C74.jpg)
Ceil-Ian Maralit
Front End Web Development Techdegree Graduate 19,434 PointsQuick question
Hi! This is my code: You'll see what my question is in the code :)
shopping_list = []
def show_help():
print("What should we pick up at the store?")
print("""
Enter 'DONE' to stop adding items
Enter 'HELP' for this help
Enter 'SHOW' to show all the items on your list
""")
def add_to_list(item):
shopping_list.append(item)
print("{} is added to your list. You now have a total number of {} item(s) on your list.".format(new_item.title(), len(shopping_list)))
def show_list():
print("The item(s) on your list are/is:")
for item in shopping_list:
print(item)
show_help()
while True:
new_item = input("> ")
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
continue
elif new_item == 'SHOW':
show_list() #This already does the right thing
continue
add_to_list(new_item)
print(shopping_list)
show_list() # I don't understand why we need to call this again here
I thought maybe it's for code efficiency. Is it? Thanks!
2 Answers
![Chandelor Simon](https://uploads.teamtreehouse.com/production/profile-photos/10610029/micro_Chandelor.jpg)
Chandelor Simon
2,242 PointsCiel-Ian: I don't understand why we need to call this again here
Chandelor: You don't actually HAVE to call it again to make the program work. This is done for the sake of being user friendly. One of the steps we wanted to take when writing this code was: make it so that the user can print at the end.
In theory: the user could just 'SHOW' the list at the end when they're finished before saying he/she is 'DONE'. Thing is: if you take out that last line of the code (show_list()) and then run it, say you're 'DONE' and then you want your list to 'SHOW' boop - the program is already over and you can't do that; nice try.
So we avoid that problem by having the list show on it's own when the user says he/she is 'DONE'.
![Ceil-Ian Maralit](https://uploads.teamtreehouse.com/production/profile-photos/10173842/micro_28459F92-CD3A-407B-BF11-B95FB66D7C74.jpg)
Ceil-Ian Maralit
Front End Web Development Techdegree Graduate 19,434 PointsOh, okay. Thank you so much to the both of you guys. Really appreciate the help! :)
Dave StSomeWhere
19,870 PointsDave StSomeWhere
19,870 PointsIf you look at the entire process it is basically:
So, it is called again at the end to finish by showing the finalized loop. Not really code efficiency but user friendliness to show the final list.