Can anyone help me understand it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone help me understand it?

If not True: Print("1") elif not ("1+1== 3"): Print ("2") else: Print("3") The NOT Boolean is quit confusing for me.😣😵😵 The answer is 2 how??

18th Apr 2021, 1:12 PM
Aditya Aryan
Aditya Aryan - avatar
7 Answers
+ 3
Your code has case and indention errors. Corrected: if not True: print("1") elif not ("1+1== 3"): print ("2") else: print("3") Output is 3. If you remove the quotes in the elif condition it will output 2. not True -> False "1+1==3" -> True (it is a string and not empty) 1+1==3 -> 2==3 -> False
18th Apr 2021, 1:45 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 2
not True means false. As first if is False it jumps to next elif . In elif 2==3 which is False but before False there is a not that makes it True . So 2 is printed
18th Apr 2021, 1:21 PM
TOLUENE
TOLUENE - avatar
+ 1
Hi! is this the full code of your program? if so, the result will be 3, not two as you indicated
18th Apr 2021, 1:20 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Hi there, this is the code https://code.sololearn.com/cl6RCLRvc196/?ref=app And I understand that not True is False but why is the answer not 1 , I mean there is not any information to say that it will be False or True in certain condition. Sorry, if I am not clear😅
18th Apr 2021, 1:46 PM
Aditya Aryan
Aditya Aryan - avatar
+ 1
Ahh, sorry for that, I pasted the code in earlier reply, can you please help..
18th Apr 2021, 1:50 PM
Aditya Aryan
Aditya Aryan - avatar
+ 1
see how your code is executed step by step: Visualize your code execution (Python, Java, C, C++, JavaScript, Ruby) https://pythontutor.com
18th Apr 2021, 1:50 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
simply In Python there are 2 types of boolean data True, False In Python, everything is True except None False [], Range (0), (),{} , "", and 0 one of boolean operator is "not" Which reverses the result Assuming a = True not a ==> False And if a = False not a ==> True I hope this helped you to understand. 😍
18th Apr 2021, 5:45 PM
Amir
Amir - avatar