Math Output Unexpected | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Math Output Unexpected

I wrote >>>10^3, and the program output 9. Any idea why the answer was not 1000?

25th Oct 2017, 5:43 PM
Chris lane
5 Answers
+ 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.
25th Oct 2017, 6:07 PM
Rrestoring faith
Rrestoring faith - avatar
+ 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
25th Oct 2017, 5:55 PM
Cool Codin
Cool Codin - avatar
+ 3
yes
25th Oct 2017, 5:57 PM
Cool Codin
Cool Codin - avatar
+ 3
@Restoring faith, lol i didn't know that cuz i didn't do much of python...... so..... anyways thanks!
25th Oct 2017, 6:10 PM
Cool Codin
Cool Codin - avatar
+ 2
Oh! that makes a ton of sense, so 9**2==81? thanks
25th Oct 2017, 5:56 PM
Chris lane