mercredi 17 novembre 2021

how booleans work with if statements in Python?

hi Guys I just want to know how Booleans work with "if" statements because it has caused some confusing and I want to understand the logic behind it and I believe that many other beginners have the same confusing. here I have an example of a car game which runs perfectly fine but I want to understand how it works :

in the below code I want to understand why when I enter "start" the Else statement gets executed FIRST and when I enter "start" AGAIN and AGAIN the If statement keeps getting executed and not the Else statement

I attached pic of the output

while True:
    word = input('enter : ')
    if word == 'start':
        if started:
            print('car already started')
        else :
            started = True
            print('car started')

Aucun commentaire:

Enregistrer un commentaire