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 !
Essayez une leçon gratuite
+ 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
Roy Weinstein - avatar
33 Réponses
+ 34
if 1st line makes no sense to you: press(^)
8th Jan 2019, 4:43 PM
Max Mustermann
Max Mustermann - avatar
+ 25
For the first part, how does it know if not True is true or false?
6th Oct 2016, 9:40 AM
+ 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 - avatar
+ 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
Olaleke Fasanye - avatar
+ 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
1st Jul 2019, 6:54 PM
Bryles - avatar
+ 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
Tom Shim - avatar
+ 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
Fernando José Torres Navarro - avatar
+ 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 - avatar
+ 2
I also don't understand how d answer is 2...
10th Jun 2020, 10:16 AM
Precious Adegeye
+ 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 - avatar
+ 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 - avatar
+ 1
it does not make any sense :) the answer is 2 tho
8th Dec 2020, 3:31 PM
Ellie Vetch
Ellie Vetch - avatar
thank you!
17th Sep 2016, 7:47 PM
Roy Weinstein
Roy Weinstein - avatar
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
Ahmed Kamal - avatar
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
I want to face challenges regarding HTML and CSS. is there any Challenger
25th Jan 2018, 8:11 AM
Ahmed Kamal
Ahmed Kamal - avatar
if not False: print(‚Äú1‚ÄĚ) output:1
28th Jun 2018, 11:24 AM
Ho Ho Yin
Ho Ho Yin - avatar
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
Ammar Muhammad Abubakar
Ammar Muhammad Abubakar - avatar
If not true may acts as if false so each and every time it will check elif part
11th Jan 2019, 4:02 AM
Adhikram Maitra
Adhikram Maitra - avatar