Count Down to Zero

Albert Wagner alwagner at tcac.net
Sat Sep 23 12:51:15 EDT 2000


Everyone seems to have had a lot of fun with this.  But Tim Peters and
others offered the only solutions: fixed point rather than floating
point.  If you live in the "real" world of business and need to deal
with things like money then deal in integer pennies, not dollars. 
Render the printout yourself.

Curtis Jensen wrote:
> 
> How come Python can't count down to zero?  Was it written by ancient
> Romans or something?
> 
> Python 1.5.2 (#7, Apr 21 2000, 13:18:02) [C] on irix646
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> float(0)
> 0.0
> >>> float( '0' )
> 0.0
> >>> i = 1.0
> >>> while i >= 0.0:
> ...   print i
> ...   i = i - 0.1
> ...
> 1.0
> 0.9
> 0.8
> 0.7
> 0.6
> 0.5
> 0.4
> 0.3
> 0.2
> 0.1
> 1.38777878078e-16
> >>>
> 
> The last one should be 0.0
> 
> --
> Curtis Jensen
> cjensen at bioeng.ucsd.edu
> http://www-bioeng.ucsd.edu/~cjensen/
> FAX (425) 740-1451

-- 
We didn't inherit the land from our fathers.
We are borrowing it from our children.



More information about the Python-list mailing list