Python SQLAlchemy Basics Working with SQLAlchemy Setting Up Our App

Hanwen Zhang
Hanwen Zhang
15,509 Points

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

Luke Impson
Luke Impson
1,203 Points

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.