CONDITIONALS & CONTROL FLOW - And


#1

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

Ok i get that its false, but only because it said True was wrong.

Am i to be using Python to calculate -(-(-(-2))) == -2 or is this something im just supposed to know, cause it didnt cover this and i wasnt expecting a math class.


#2

Math is a big part of programming. This exercise is meant to be completed visually, not with the aid of the computer.

If you have not studied multiplication of negative numbers then you will be at a bit of a disadvantage with this one.

-1 * -1 == 1

-1 * 1 == -1
  • A negative times a negative yields a positive product.

  • A negaive times a positive yields a negative product.

  • A negative sign on a number is the same as -1 times the positive number.

    -22 == -1 * 22

That shows that wherever we see a negative sign we can insert a 1 *.

-(-(-(-2)))

same as,

-1 * -1 * -1 * -1 * 2

Now count the negative 1’s. Four in all. When the number of negatives is even, the product is positive. When the number of negatives is odd, the product is negative.

The above can be reduced to 1 * 2 which is 2.

Now let’s consider the and operator. These expressions short-circuiton False, meaning ALL operands must yield True or the expression will yield False.

2 == -2  =>  False

The rest of the expression is ignored since the first operand is False.


#3

Ok then i had the right answer through that process, but yah its been a long time since i had to think in terms of negative times a negative equals a positive.


#4

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