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?

10th Nov 2017, 6:48 AM
Jinsu
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!
10th Nov 2017, 7:19 AM
blackcat1111
blackcat1111 - avatar
0
every condition returns true or false, so just "true" basically means always yes (or no in this case because of the not)
10th Nov 2017, 6:56 AM
Jeremy
Jeremy - avatar