0

python if

a = int(input()) b = int(input()) if a or b == 1: print ("11") else: print ("else") input: 2 2 output: 11 Why???????

22nd Apr 2019, 11:39 AM
Life1219
Life1219 - avatar
1 Answer
+ 3
You want to write a or b have to be 1, right? a==1 or b==1 Your condition instead means: if a exists (!=0) or b==1 'if x' only checks if x - whatever it is - is not False. So any number != 0, any container with at least one item, any string with at least one sign in it (even space) will be True.
22nd Apr 2019, 11:41 AM
HonFu
HonFu - avatar