+ 1

If else logic is not clear in the given scenario

if 1 + 1 == 2: if 2 * 2 == 8: print("if") else: print("else") Ans: Else

14th Sep 2020, 4:39 PM
Abhi
Abhi - avatar
2 Respostas
+ 1
It is too simple, always nearest condition of parentheses will be executed first, here 1+1 ==2 (true), But 2*2 is not equal to 8, so the else's block will be execute.
14th Sep 2020, 7:05 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 2
First 1+1=2==2 true Second 2*2=4==8 false So output will be Else
14th Sep 2020, 4:47 PM
Vadivelan