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!
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
Natalie Heyde1,736 Points
Why do we need to put the show_list() function at the end?
I was just wondering why we need to put the show_list() function at the end of the file? For some reason my code worked fine without it/looked identical to the example code (maybe out of luck), with the only difference being not putting show_list() at the end. What is the purpose of including it there?
Caleb Kemp12,754 Points
Your right, sorry I did misunderstand. So, I think the question is, why does Craig have a call to
show_list() at the end since it doesn't seem to do anything? right?
Well, with the
show_list()at the end, after you have finished making your list and type in "DONE", it will print out a list of the items you added to the cart like so
Here's your list: eggs cheese milk etc.
Without it (
show_list()), it will not print the list once it finishes. I hope that helps
One thing I wanted to mention is what Craig mentions quite often, and that's that we're not going to break anything by changing the code. So this is a good example.
Test 1. # show_code() With it commented out, run the code, and see what happens.
Test 2: show_code() Uncomment it, then see.
I was a bit confused about various aspects of the code myself, so I broke the code, changed it, commented it out, and that helped me see the end result.
In this case - as the comments indicate - the shopping list displays when DONE.