+ 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?
2 odpowiedzi
+ 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 ;))
0
perfect explanation