This is the given code if not True: print("1") elif not(1+1==3): print("2") else print("3") I know the answer is 2 but what does the first print("1") do? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
+ 12

# This is the given code if not True: print("1") elif not(1+1==3): print("2") else print("3") I know the answer is 2 but what does the first print("1") do?

17th Sep 2016, 6:45 PM
Roy Weinstein
33 Réponses
+ 34
if 1st line makes no sense to you: press(^)
8th Jan 2019, 4:43 PM
Max Mustermann
+ 25
For the first part, how does it know if not True is true or false?
6th Oct 2016, 9:40 AM
nick
+ 20
if not True: print("1") #prints 1 if not True is True elif not(1+1==3): print("2") #prints 2 if 1+1 is not 3 else: print("3") #else prints 3
17th Sep 2016, 7:04 PM
Zen
+ 15
In basic english: If true is not equal to true, print 1 Else, if 1 + 1 is not equal to 3, print 2 Else, print 3
18th Dec 2018, 10:19 AM
Olaleke Fasanye
+ 12
What people seem to forget is how the "if statement" works. In other words, the expression for the "if statement" needs to be evaluated as 'True' in order to continue with the statement, otherwise it moves on to the next part of the code. From the example, if not True: # if False => skips the next statement print("1") elif not (1 + 1 == 3): # else if True => continues with the statement print("2") else: # since the previous statement was true, '2' is printed and the next statement is skipped print("3")
29th Jul 2020, 11:29 PM
Miroslav Valov
+ 11
2
1st Jul 2019, 6:54 PM
Bryles
+ 8
When nothing is declared, it's presumend as True. So since nothing was declared on line 1; the "thing" your comparing is True. Hence True not True? The answer is False. So we move to line 3.
2nd Sep 2020, 12:31 AM
Tom Shim
+ 7
if not True: # not True is False print("1") elif not(1+1==3): # not(1+1==3) is True print("2") else print("3") # the previous condition is fulfilled, therefore, this not reaches evaluated
3rd Oct 2016, 11:58 AM
Fernando José Torres Navarro
+ 6
Explanation: First suite: If statement is always true, so “1” will not be printed because of “not operator” (if not True = False). Second suite: (1+1 == 3) is false but there is a “not operator” so it will become true. It will print “2”. Third suite: Will not be read since the second suite is already true.
29th Jul 2020, 4:29 PM
Cath
+ 2
I also don't understand how d answer is 2...
10th Jun 2020, 10:16 AM
+ 2
if/elif statements are only executed if the condition is True. Since the first line is not True, it is not executed. Hence, moving on to the next statement.
12th Sep 2020, 6:03 AM
Danker
+ 1
For the thing, dont think to hard about it. It says if not true print 1. Not True is False, so you don't even have to look at it, because it is false.
28th Nov 2020, 12:49 AM
H P
+ 1
it does not make any sense :) the answer is 2 tho
8th Dec 2020, 3:31 PM
Ellie Vetch
0
thank you!
17th Sep 2016, 7:47 PM
Roy Weinstein
0
the second logic is to be applied as the question ends there the third logic is an extra one.
23rd Sep 2016, 3:27 AM
Ahmed Kamal
0
i still don't get the first line. what does if not true print 1 means? I what case would the output be "1"
24th Jan 2018, 12:26 PM
Sandra Stutz
0
I want to face challenges regarding HTML and CSS. is there any Challenger
25th Jan 2018, 8:11 AM
Ahmed Kamal
0
if not False: print(“1”) output:1
28th Jun 2018, 11:24 AM
Ho Ho Yin
0
The answer is 2 if not True: print("1") elif not (1 + 1 == 3): print("2") else: print("3")
31st Aug 2018, 2:28 AM