Python Challenge - Level 0
Hint: try to change the URL address.
As the "0" indicates, this is just a warm up.
The naive way to solve it: multiply by 2 in a loop:
>>> k = 1 >>> for i in range(38): ... k *= 2 ... >>> k 274877906944
** for power:
>>> 2**38 274877906944
In REPL the result will be printed; or you can explicitly print the result by calling
>>> print(2**38) 274877906944
**, you can also use
>>> pow(2,38) 274877906944
>>> print(pow(2,38)) 274877906944
Multiply by 2 is equivalent to shifting the binary representation left by one:
>>> 1<<38 274877906944
Wait, why 38? what is implied?
If you are coming from C/C++, Java or other languages, you know that there are multiple types just for integers:
long, and even
BigInteger beyond 64-bit. However that is not the case in Python:
>>> type(2**3) <class 'int'> >>> type(2**38) <class 'int'> >>> type(2**380) <class 'int'>
So 38 is a good(and random) example to show a
int larger than 32-bit.
Similar for float type, in Python it can be arbitrarily large, no
>>> type(2**3.8) <class 'float'> >>> type(2.0**38) <class 'float'>
And it will jump to