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 SQLAlchemy Basics Working with SQLAlchemy Setting Up Our App

What does app_running mean in this video? Can I just name it any other name or it is a built-in function?

def app():

app_running = True #this line here

while app_running:

    choice = menu()
    if choice == '1':
        # add book
        pass
    elif choice == '2':
        # view books
        pass
    elif choice == '3':
        # search book
        pass
    elif choice == '4':
        # analysis
        pass
    else:

        print('GOODBYE')

        app_running = False #also here

Thank you

1 Answer

app_running is a variable, not a function. It really wouldn't matter what the variable was called as long as every instance of app_running was renamed. Your code won't run properly if you don't rename every instance of it. It's because you've set app_running equal to True. app_running is used as your condition under which your while statement will run. The while statement evaluates an expression and loops as long as that expression is True. So a 'while True' loop will run infinitely because True always equals True. Thus, since app_running is True, the following code will continue to loop until app_running = False. In this case, app_running is set to False when 'choice' is set to something other than 1, 2, 3, or 4. When it does not meet any of these if or elif statements, it follows the else statement, where 'GOODBYE' is printed and app_running is set to False, and the while loop ceases because app_running no longer is True.