Re: Looping using iterators with fractional values

2005-01-01 Thread beliavsky
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 variab

Re: Looping using iterators with fractional values

2005-01-01 Thread Reinhold Birkenfeld
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 There's a glitch there, though - should be range(1, 10). Reinhold PS: I'm wondering whe

Re: Looping using iterators with fractional values

2005-01-01 Thread Mike Meyer
"drife" <[EMAIL PROTECTED]> writes: > Hello, > > Making the transition from Perl to Python, and have a > question about constructing a loop that uses an iterator > of type float. How does one do this in Python? > > In Perl this construct quite easy: > > for (my $i=0.25; $i<=2.25; $i+=0.25) { > pri

Re: Looping using iterators with fractional values

2005-01-01 Thread Steven Bethard
Mark McEahern wrote: drife wrote: Hello, Making the transition from Perl to Python, and have a question about constructing a loop that uses an iterator of type float. How does one do this in Python? Use a generator: >>> def iterfloat(start, stop, inc): ... f = start ... while f <= stop:

Re: Looping using iterators with fractional values

2005-01-01 Thread Reinhold Birkenfeld
drife wrote: > Hello, > > Making the transition from Perl to Python, and have a > question about constructing a loop that uses an iterator > of type float. How does one do this in Python? > > In Perl this construct quite easy: > > for (my $i=0.25; $i<=2.25; $i+=0.25) { > printf "%9.2f\n", $i; >

Re: Looping using iterators with fractional values

2005-01-01 Thread Mark McEahern
drife wrote: Hello, Making the transition from Perl to Python, and have a question about constructing a loop that uses an iterator of type float. How does one do this in Python? Use a generator: >>> def iterfloat(start, stop, inc): ... f = start ... while f <= stop: ... yield