Looping using iterators with fractional values

beliavsky at aol.com beliavsky at aol.com
Sat Jan 1 17:46:17 EST 2005

Mike Meyer wrote:

>Or - and much safer when dealing with floating point numbers - iterate
>over integers and generate your float values:

>for j in range(1, 9):
>   i = j * .25
>   print "%9.2f" % i

I agree with this suggestion. As an historical aside, Fortran had loops
with floating point variables for decades, but in 1995, the first
standard in a while to REMOVE features, this was one of the few things
deleted. The Fortran standards committee is very conservative about
creating backwards incompatibilities, but they must have thought loops
with floating point variables are so error-prone -- and alternatives
with integer counters are so easy to write -- that they put their foot
down. I know the OP is asking about Python, but the principle is the

More information about the Python-list mailing list