what does this code mean? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

what does this code mean?

INPUT: if not True: print("1") elif not (1 + 1 == 3): print("2") else: print("3") OUTPUT: 2 what is the meaning of (if not True), true respect to what?

9th Jul 2017, 6:11 PM
Youssuf Abramo
Youssuf Abramo - avatar
2 Answers
+ 9
if not True: is equivalent to: if not (42 == 42): The first form give just the result of a condition instead the condition itself... 'if not True' will only execute if 'not True' is True, but is always False: so, the code go to the next 'else' statement which is an 'elif' (stand for 'else if'). The second condion is 'not (1+1==3)' which would be evaluate as 'not False' which is True, then code print("2") is executed... The third and last condition (simple 'else') is never ran, because one of the previous is True (last 'else' statement will run only if all previous are False: as soon as a True condition is reached, the corresponding block of instructions is executed and the the code exit all the 'if/else' structure ;))
9th Jul 2017, 6:29 PM
visph
visph - avatar
0
perfect explanation
23rd Jul 2017, 10:50 AM
Kirti Bahirwani
Kirti Bahirwani - avatar