Integer division is the default for the / operator in Python <3.0. It has a behavior that seems a little strange. He returns the dividend without a remainder.
>>> 10 / 3 3
If you are using Python 2.6+, try:
from __future__ import division >>> 10 / 3 3.3333333333333335
If you are using a lower version of Python, you will need to convert at least one of the numerator or denominator to a float:
>>> 10 / float(3) 3.3333333333333335
In addition, math.ceil always returns a float ...
>>> import math >>> help(math.ceil) ceil(...) ceil(x) Return the ceiling of x as a float. This is the smallest integral value >= x.
Tim McNamara
source share