The above answers are correct, however, importing the math
module just for this one function usually feels like a bit of an overkill for me. Luckily, there is another way to do it:
g = 7/5
g = int(g) + (not g.is_integer())
True
and False
are interpreted as 1
and 0
in a statement involving numbers in python. g.is_interger()
basically translates to g.has_no_decimal()
or g == int(g)
. So the last statement in English reads round g down and add one if g has decimal
.