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

Question

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

Answer

Any time we see a complicated looking expression, like -(2 ** 3) < 2 ** 2 and 100 / 2 <= 20 - 10 * 2, it can be helpful to break it down into its parts like below.

# First, look at the left side of the AND
left_half = -(2 ** 3) < 2 ** 2
left_half = -(8) < 4  # True

# Now look at the right side of the AND
right_half = 100 / 2 <= 20 - 10 * 2
right_half = 50 <= 0  # False

# Finally, we can combine these halves around the AND
# And since we know the truth value of either side, we know the end result!
bool_result = left_half and right_half  # False

You don’t need to write out new variables for each step, of course. And it’ll only get easier with practice. But mentally breaking down each side can definitely help!

7 Likes

2 posts were split to a new topic: How exactly do we know if it is to be true/false?

3 posts were split to a new topic: Why bool_three came out to be False?

how is this expression true?
10 % 10 <= 20 - 10 * 2

Break it down…

10 % 10      =>  0

20 - 10 * 2  =>  20 - 20  =>  0

Now compare the evaluations…

0 <= 0       =>  True
3 Likes

Thank you!
i was calculating 10*2 as an exponential all the time! that’s why i got it wrong :sweat_smile:

1 Like

bool_four = -(1 ** 2) < 2 ** 0 and 10 % 10 <= 20 - 10 * 2
-1 < 1 and 0 <= -80
True and False
False
I had an error message for this which shouldnt be

Sorry im wrong: its 20 - 10 * 2 and not 20 - 10 **2

A = -(1 ** 2) < 2 ** 0
B = 10 % 10 <= 20 - 10 * 2

Figure out A, first.

-(1 **2)    => -(1)  =>  -1
2 ** 0      =>  1

A = -1 < 1  =>  True

Now figure out B

10 % 10      =>  0
20 - 10 * 2  =>  20 - 20  =>  0

B = 0 <= 0   =>  True

Now evaluate with and,

A and B  => True and True  =>  True
1 Like

bool_one = False and False

bool_two = -(-(-(-2))) == -2 and 4 >= 16 ** 0.5

bool_three = 19 % 4 != 300 / 10 / 10 and False

bool_four = -(1 ** 2) < 2 ** 0 and 10 % 10 <= 20 - 10 * 2

bool_five = True and True

I typed this out, but I received an error message, why?

Because we are not supposed to copy the expressions, but visually evaluate them and write the final result.

bool_one = False
...
bool_five = True

If one does not do these exercises in earnest, meaning actually using only our brain to evaluate the expressions, one can never hope to have the concepts stick. We should be able to just look at an expression, take it apart in our mind, and reduce it to a single boolean. It is a type of algebra in that operators have precedence (order of operations) just as they do in maths.

If not in our mind, then on paper. Simplify. For instance, what does,

-(-(-(-2)))

reduce to? Remember, brackets have precedence, too. We start on the inside and work our way out.

-2

can be rewritten as,

-1 * 2

and put back in,

-(-(-(-1 * 2)))

Now we can replace the other negative signs with -1 *,

-1 * (-1 * (-1 * (-1 * 2)))

Now we carry out the multiplication to remove the brackets.

-1 * (-1 * (-1 * -2))

-1 * (-1 * 2)

-1 * -2

 2

So -(-(-(-2))) reduces to 2; and, 2 == -2 will be False. Given that we are dealing with an AND expression, we can stop here since and short-circuits on False. The result is thus, False.

For practice, though, let’s evaluate the other operand…

4 >= 16 ** 0.5

Recall that rational exponents give us the root of a number. “Sixteen to the one-half” is the same as saying, “The square root of sixteen”.

4 >= 4

is True, but that doesn’t matter in this case, owing to the above short-circuit result.

5 Likes

Hi,

what about this? why is this wrong please? Thank you!!! :grinning:

Make me true!

bool_two = true not false and false or true

Make me false!

bool_three = false not true and true or false

Make me true!

bool_four = true or not true and true

Make me true!

bool_five = not not true and false or true

In one session it stands this :
-(-(-(-2))) == -2 and 4 >= 16 ** 0.5
But I have question how is this -(-(-(-2))) calculated to 2? I dont really understand this.

PS: I got it after searching on google. I am sorry if I bothered you guys with this, but I really forgot math from school :smiley: .

Fully explained only two posts up.

Hey,i dont understand WHY 10%10 gives 0,maybe i missed or forgot a explanation? Im reading it as the 10 percent of 10 is 1,not 0,so yea.

2 Likes

Guessing is really bad for your ability to reason, so if you don’t KNOW what something means then go find out, even if you have some guess.

If you google for python operators, or perhaps a tutorial and check whatever part they have on operators, then I’m sure you’ll find what it does. (and more importantly, you can do the same for next thing you’re not sure about)

Its not the percentage. It means how often fits 10 in 10 and is there anything left in this Example…if not so result is 0.
19 % 4 => 4 fits 4 times in 19 so 16
4x4 => 16
Now you have 3 left 19-16=3
Result of 19 % 4 == 3 is True :slight_smile:
Please forgive my Language skills im not good in English but i want to learn programming.

8 Likes

sorry guys, how can this be False? Is there a typo? aren’t both sides true?

grafik

1 Like

As I recall there were four - signs in the original problem, before the system error cropped up.

-(-(-(-2))) == -2

which is False, so will short-circuit the AND expression and yield False without evaluating the second operand.

1 Like

got it, but didn’t know of a system error. thx

1 Like