[Tutor] a print puzzle

Richard D. Moores rdmoores at gmail.com
Thu Dec 2 12:06:00 CET 2010


>>> s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1]
>>> sum(s)
0.9999999999999999
>>> print(sum(s))
1.0      Why?
>>> f = 0.9999999999999999
>>> f**100
0.9999999999999889
>>> print(f**100)
1.0      Why?
>>> f**10000
0.9999999999988898
>>> print(f**10000)
0.999999999999
>>> from math import fsum
>>> fsum(s)
1.0
>>> from math import fsum
>>> fsum(s)
1.0        See <
http://docs.python.org/py3k/library/math.html?highlight=fsum#math.fsum>

The "Why?"s mark what are puzzles for me.

I see nothing in the doc for print() that explains these: <
http://docs.python.org/py3k/library/functions.html?highlight=print#print>,
but I'm sure a Tutor can.

Dick Moores
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101202/fdf5f48b/attachment.html>


More information about the Tutor mailing list