Tag: exit program

National 5 – Boolean

A boolean variable is used to store True or False values. This can be very useful in programs, as you can use it in the program logic.

In the example below the user has to choose to exit the program, this sets the quitProg boolean variable to True which makes the result of the condition in line 3 False. Notice that True/False have capitals at the start of the value.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
quitProg=False

while not quitProg:

    #Program does stuff here
    
    choice=input('Do you want to quit (Y/N):')
    if choice in 'Yy':
        quitProg=True

print('Exiting program')