+ 2
Math Output Unexpected
I wrote >>>10^3, and the program output 9. Any idea why the answer was not 1000?
5 Respuestas
+ 7
If there was no ^ operator, the result would be an error, not 9 😛.
^ is a bitwise (exclusive or) operator.
a^b
If one bit from a or b is 1, then it takes the 1. As long as both from a and b are not 1.
If a = 10 and b = 3.
10 in binary is:
1010
3 in binary is:
0011
1001 is the result of a^b.
1001 in base 10 is 9.
So, 10^3 = 9.
+ 3
There is no carrot symbol or the '^' operator in python.
You need to use '**' This operator in order to raise a number to the power of the other number provided.
ex.. 10 ** 3 == 1000
+ 3
yes
+ 3
@Restoring faith, lol i didn't know that cuz i didn't do much of python...... so..... anyways thanks!
+ 2
Oh! that makes a ton of sense, so 9**2==81?
thanks