How exactly do we know if it is to be true/false?


#1

And

A very unhelpfull answer… [in the backlinked topic]
The question is how do we know if the anwer is True/False?
If its True the code works? Is this how we know that it is True?
If we get an error message, that is how we know it’s False?

HOW EXACTLY DO WE KNOW IF IT IS TO BE TRUE/FALSE?


How are we supposed to evaluate if these are True or False?
#2

By visually evaluating it, using precedence rules.

-(2 ** 3) < 2 ** 2 and 100 / 2 <= 20 - 10

Do an inventory of the operators and set out a plan to follow order of operations. It’s not necessarily a left to right thing when AND is involved. Just look for an operand that is False. If there is one, it short-circuits and yields False. Pick the obvious, whenever possible.

100 / 2

is not less than or equal to

20 - 10

Done deal. Who cares what,

-(2 ** 3) < 2 ** 2

yields up. It won’t matter. Just remember that precedence is key.

-8 < 4

is True. True and False is always, False. See why we look for the False first?

This is a skill. If one doesn’t train our eyes to read these expressions, we’ll likely never take advantage of what they offer us in terms of fine tuned logic in our control flow. We won’t have trained our brain, either.

Bookmark a page on operator precedence so you have quick access to the reference until you have it memorized. Construct some basic truth tables so you can memorize them, as well. That’s how we solve these expressions without the aid of the computer.