Operator Precedence | SoloLearn: Learn to code for FREE!

+2

Operator Precedence

What is the result of this code? x = 4 y = 2 if not 1 + 1 == y or x == 4 and 7 == 8: print("Yes") elif x > y: print("No")

4/14/2020 8:28:20 AM

M∆π∆$

5 Answers

New Answer

+4

Precedence for if statement is in the following order + == not and or 1+1 is done first, then all == in left to right order. So now you have not true or true and false then the boolean not is applied false or true and false then the and comparison is done false or false then the or comparison is done resulting in false Then the elif is done. Resulting in true and "No" is output.

+3

No is answer as In if case and is firstly processed which results in 0 then or is processed not 2==y or x==1 this also results in 0 , so it goes for elif which results No.

+3

M∆π∆$ This sounds like a homework question which could have been resolved by running the code yourself. Or are you looking for the logic behind the result?

+2

Well,I guess I was just a little confused about operator precedence.Thanks for helping me out

0