mercredi 22 février 2017

Python second "if statement" negates first one

If I have two if statements followed by an else then the first one is essentially ignored:

x = 3
if x == 3:
    test = 'True'
if x == 5:
    test = 'False'
else:
    test = 'Inconclusive'

print(test) 

Returns:

Inconclusive

It seems to me that since the first if statement is True then the result should be "True". In order for that to happen the second if statement must be changed to "elif". Does anyone know why?

Aucun commentaire:

Enregistrer un commentaire