In the code below I expect it prints reach here 2
, because none of the variable meets the conditions of the if
statement However, the code prints reach here 1
.
m = 1
type1 = 'a'
type2 = 'x'
if m > 1 and type1 == 'b' and type2 == 'y' or 'z':
print('reach here 1')
elif type1 == 'a' and type2 == 'x':
print('reach here 2')
May anyone explain how come the code is able to "reach here 1
", and help me correct the if
statement so that it prints reach here 1
only when m > 1
and type1 = 'b'
and type2
equals to either 'y'
or 'z'
? Appreciate!