+ 3

Explain this code. How yes come???

x=2 y=1 if 1+1!=y or x==x and 7==8: print("yes") elif x>=y: print("no") output :-yes

12th Jun 2017, 6:07 AM
Asif Mohd
Asif Mohd - avatar
4 ответов
+ 16
7==8? False.... (A) x==x? True.... (B) B && A... False...(C) 1+1!=y?... True...( D) D || C... True.. Thus "yes"
12th Jun 2017, 6:09 AM
Frost
Frost - avatar
+ 4
@debug the OR operator has a lower precedence than the AND operator, so && first before ||.
12th Jun 2017, 6:23 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 2
x==x(true) && 7==8(false) --- 0(False) 1+1!=y(true) or 0(false) --- True output "yes" the other statements inside the if... else block is left over even if they evaluates to true.
12th Jun 2017, 6:14 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
- 5
1+1 not equal to 1 - true -----or----- x is equal to x - true ___________________________________________________________________ True. -----and----- 7 is equal to 8 - false __________________________________________________________________ False. Hence the answer should be false. Try out in PC.
12th Jun 2017, 6:18 AM
debug
debug - avatar