[SOLVED] do not understand two lines of code from Python

Issue

I do not understand the quite_program = False and quite_program = True. What do they mean? For this code, I think it will execute the code chunk, while not quit_program but I do not know how to understand it. It means if quit_program is not False? I kind of confuse and thanks so much for your help.

def print_menu():
    print("Today's Menu:")
    print('   1) Gumbo')
    print('   2) Jambalaya')
    print('   3) Quit\n')

quit_program = False

while not quit_program :
    print_menu()
    choice = int(input('Enter choice: '))
    if choice == 3 :
        print('Goodbye')
        quit_program = True
    else :
        print('Order: ', end='')
        if choice == 1 :
            print('Gumbo')
        elif choice == 2 :
            print('Jambalaya')
        print()

Solution

In your program, quit_program is used to stop the execution of the program as desired. When checking while loop condition initially quit_program = False then not quit_program gives True.

The while loop keeps executing until the quit_program = True. If quit_program = True then not quit_program gives False and then while loop will ends the execution(running). It means this while loop ends only if the choice == 3 condition is True.

Therefore, your program is executing(running) until you give the input as 3.

Answered By – nilrj

Answer Checked By – Mildred Charles (BugsFixing Admin)

Leave a Reply

Your email address will not be published.