+ 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??
7 Respuestas
+ 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
+ 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
+ 1
Hi! is this the full code of your program? if so, the result will be 3, not two as you indicated
+ 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😅
+ 1
Ahh, sorry for that, I pasted the code in earlier reply, can you please help..
+ 1
see how your code is executed step by step:
Visualize your code execution
(Python, Java, C, C++, JavaScript, Ruby)
https://pythontutor.com
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. 😍