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

Mayank Munjal
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Mayank Munjal
Front End Web Development Techdegree Graduate 18,120 Points

Why do we have to call the show_help function twice?

Why do we have to call the show_help function twice? Once before the while loop and once in the loop. Why couldn't we directly call it in the while loop?

2 Answers

Hi Mayank Munjal,

Let me first explain the code that Mr. Love uses.

show_help()

while True:
    if new_item == "HELP":
        show_help()

This displays all the help options when the program is launched so that the user will know what commands he can use. Then the loop starts and the user can enter a '''new_item''' if that item is HELP then it will show_help() again, if it's a new item then that will be added to the list etc.

I think what you mean is this:

while True:
    show_help()

    if new_item == "HELP":
        show_help()

This isn't bad, but its kind of unnecessary it prints out show_help() every single time that the user is prompted to enter a new_item. So unless if you know that the person you are writing this program for has bad memory its not useful.


sig

the first one is put in there because if you don't have it you go straight into the loop, so you'll see the "> " so you need to call it first, then have it a second time if the person uses the help function