I have a 100 digit number and I am trying to put all the digits of the number into a list, so that I can perform operations on them. To do this, I am using the following code:
for x in range (0, 1000):
list[x] = number % 10
number = number / 10
number = int (number / 10)
In Python 3,
number / 10 will return try to return a
float. However, floating point values can't be of arbitrarily large size in Python and if
number is large an
OverflowError will be raised.
You can find the maximum that Python floating point values can take on your system using the
>>> import sys >>> sys.float_info.max 1.7976931348623157e+308
To get around this limitation, instead use
// to get an integer back from the division of the two integers:
number // 10
This will return the
int floor value of
number / 10 (it does not produce a float). Unlike floats,
int values can be as large as you need them to be in Python 3 (within memory limits).
You can now divide the large numbers. For instance, in Python 3:
>>> 2**3000 / 10 OverflowError: integer division result too large for a float >>> 2**3000 // 10 123023192216111717693155881327...