I wanted to start by asking here about this. This was given to me as part of an exercise at codeacademy.com and confused me for the better part of an hour.
Take a look at the following code block:
bool_one = 40 / 20 * 4 >= -4**2
Now, I evaluated that as being "8 >= 16" which is False.
However, the codeacademy.com terminal says it's True. When I started writing debug code lines, I found the issue was in how "-4**2" gets evaluated. When I run it on the terminal at CodeAcademy as well as on my local linux system, "-4**2" in Python comes out to "-16"... which is contrary to everything I have learned in all my math classes as well as every single calculator I have run it on. Whether I run it as "-4 * -4" or "-4^2" or even, using the "x^y" key, "-4 [x^y] 2", it still comes out as "16". So, how is python coming out with "-16" for "-4**2"?
Can someone please clarify this for me?
TIA.
(-4)**2 != -4**2
.-4**2 == -(4**2) == -16
. Remember your order of operations. Exponentiation comes before multiplication.