Confused about True False value in a program

command = “”
started = False
print(‘Type help for further info.’)
while True:
command = input(’> ‘).lower()
if command == ‘start’:
if started:
print(‘Car is already started!’)
started = True
print(‘Car started…Ready to go!’)
elif command == ‘stop’:
if not started:
print(‘Car is already stopped!’)
started = False
print(‘Car stopped!’)
elif command == ‘help’:
start - to start the car
stop - to stop the car
quit - to stop’’’)
elif command == ‘quit’:
print(“I don’t understand that…”)

This is a program which Mosh showed in his python course on youtube. But I couldn’t understand about the ‘started’ variable. I mean how does the True False value works here. Anyone can briefly explain?
TIA and sorry for my bad English

1 Like

started stores a boolean. It’s either True or False.

If we give the command start, then we check to see if started is True or False. If started is True, then we print out that the car has already started. If started is False, then we change the started variable to True.

Changing the started variable from False to True will change the way that the program runs when it reaches a line that says if started:

1 Like

Thank you so much. Could you please also explain the ‘if not started’ part?

Hi Richard777,

You mentioned that “If started is True, then we print out that the car has already started.” however, at the beginning of program we put “False” for “started” that means car is not started yet.
So, for the first time we type “start” program should say “car started…ready to go!” but it says ‘car is already started!’
it is confusing for me and I cannot understand it.