0
The question on the Boolean logic part
I am learning the python Boolean logic part now, but I donât understand the question of ânotâ on the test. The question says What is the output? If not true: Print(â1â) elif not (1 + 1==3): Print(â2â) else: Print(â3â) I understand that not true is false and not false is true but, I donât get what the whole question is talking about. What is not true? Isnât there supposed to be an equation on the top? Or is something wrong with my tab?
2 Answers
+ 3
A classical "if" statement goes like this:
if (condition):
(what to do if condition is true)
Said condition will always return "True" or "False". So, imagine a program:
if True:
print("1")
As the "True" condition returns... well, True, the program will go ahead and output 1. Now, back to the original question:
if not True:
print("1")
Not True, rather obviously, evaluates to False and hence the first statement is not fulfilled. Next line:
elif not (1 + 1 == 3):
print("2")
As the condition (1 + 1 == 3) returns False, but there is a "not", it returns True instead and 2 is the output.
Hope you learned something from this incredibly lengthy explanation!
0
every condition returns true or false, so just "true" basically means always yes (or no in this case because of the not)