Mystified by "And"



<The hint says “Be careful with bool_four—there’s a big difference between -1 ** 2 and (-1) ** 2! This is meant to be tricky.” Perhaps it has been too many years since eighth grade… how in the world is “(-1) ** 2” any different from “-1 ** 2”? The problem is: “-(1 ** 2) < 2 ** 0 and 10 % 10 <= 20 - 10 * 2”. As far as I can tell, the first part (before “and”) is “-1 < 2” and the part after “and” is “1 <= 20 - 20”. I cannot figure out how I could possibly be getting anything but “True and False” for the answer.>


bool_four = True and False

<do not remove the three backticks above>


math has order of operations, do you remember this from eight grade? (multiplying comes before sum)

so ** comes before -, so -1**2 is 1**2 which is 1, so then we get -1

while (-1)**2 can also be written as -1 * -1 which is 1


Oooohhhhhhhhh, of course! Thank you. I was beating my head against the wall. I was thinking they had screwed up the order of operations by failing to recognize that 20-10*2 is zero, not twenty. I was confident they wouldn’t screw up the order of operations, though, so I knew the problem must have been me.


Okay, so you understand everything now? Any further assistance needed?


That first question pertaining to -1 didn’t affect the outcome of my code. The real reason I posted the question was to address the second part. The second part appears to be “1 <= 0” which should be false.


i see your confusion, which is here:

10 % 10

this is the modulo operator, not the division operator. 10 / 10 is 1, that is true enough. But what is 10 % 10? Remember what the modulo operator does?


Okay, lets do an example for 16 % 5

We are at a party, with a total of 5 people. And we have a pie, and we cut the pie in 16 pieces (or we have 16 candy-bars, whatever, doesn’t matter), and i am going to everyone as much pieces as pie of possible,

can i give everyone one piece of pie? yes
can i give everyone two pieces of pie? yes
can i give everyone three pieces of pie? yes
can i give everyone four pieces of pie? no

so i can give a maximum of 3 pieces of pie to every person, if i do, how many pieces do i have left? One piece, so the remainder is 1

Now, apply this same logic for your problem.


Thank you! I appreciate all your help! No further assistance needed.


you’re welcome. Now you see what the outcome of the math is, you also understand where the true is coming from.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.