+ 1
If else question
X=True Y=False Z=False if X or Y and Z: print ('yes') else: print ('no') Isn't this expression supposed to print 'no'?
9 Respostas
+ 1
Becuase x is true the rest of the exspression is ignored and prints yes
+ 1
I think and has a higher priority than or so Y and Z evaluates first resulting in False then X or false results in True.
+ 1
You got indentation error for print
Code: -
If X or Y and Z=='False':
print('yes')
Else:
print('no')
0
'or' operator means any of the one if is True then will print 'yes'.
0
Ok thanks
0
It prints yes because and has higher precedence order than or.
You can use parentheses to control operation precedences.
0
priority order is NOT AND OR
use this
Y AND Z = FALSE
THEN
X OR FALSE = TRUE SO answer is TRUE
0
Priority order- NOT>AND> OR
Therefore;
If X OR Y AND Z = IF X OR (Y AND Z)
So you will solve brackets first.
This implies, Y AND Z= FALSE AND FALSE
= FALSE
NOW X OR FALSE = TRUE OR FALSE
= TRUE
THUS , this code will print 'yes'.
0
Yes because you used 'or' statement so one condition is required to be true.
If X 'or' y and z
For detail these is Logical operators
Or
And
Not