0

Help explain. And what is the output of this code.

if not true: print (1) elif not (1+1==3) print ("2") else print ("3"). in line 1. what is not true to print 1

30th Dec 2016, 6:45 PM
stephen haokip
stephen haokip - avatar
3 odpowiedzi
+ 5
print(1) executes only if the condition is true, "not true" means false so it moves to next condition, 1+1==3 returns false because 1+1==2 but the not in front of it reverses it to true thus print("2") gets executed, third statement is skipped because one condition was satisfied.
30th Dec 2016, 6:50 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
The result of a condition is false or true. Obviously, "false" and "true" are the keywords to say false or true :P Well, you don't have to read "if not true" as human, but as short computer code writing, as: if not (condition)... the parenthesis aren't required so you can write "if not true", as "if not (true)", then "true" is the result of the condition, as your "elif not (1+1==3)" will be evaluate to "elif not (false)"... [ EDIT ] And the output is 2
30th Dec 2016, 7:35 PM
visph
visph - avatar
0
if not true: #if it is wrong, print 1, print (1) elif not (1+1==3) # else, if this is true, i.e. "not 1+1=3", which is true print ("2") #print 2, because "not 1+1=3" is true else print ("3").
13th Jan 2017, 7:28 AM
ysyinbaker