mardi 21 avril 2020

In python when using an if statement with or's why does is it ignore the conditions [duplicate]

x = 5
if x == 2 or 4 or 6:
    print("Even")
elif x == 3 or x == 5 or x == 7:

    print("Odd")

I know the or statements should be like the bottom line but I am curious to why when run the output is always even, despite it not being in the if line. When run with the top line like the bottom it works however it treats the bottom as an else so if x was 30 it would still fall into 'odd'. Any explanation to why this is would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire