Re: [Tutor] a print puzzle

2010-12-02 Thread Steven D'Aprano
bob gailer wrote: On 12/2/2010 2:09 PM, Richard D. Moores wrote: [snip] I found nothing that helped as much as you have already. In the reference (for 2.6.2) under print statement I find: "print evaluates each expression in turn and writes the resulting object to standard output (see below

Re: [Tutor] a print puzzle

2010-12-02 Thread bob gailer
On 12/2/2010 2:09 PM, Richard D. Moores wrote: [snip] I found nothing that helped as much as you have already. In the reference (for 2.6.2) under print statement I find: "print evaluates each expression in turn and writes the resulting object to standard output (see below). If an object is

Re: [Tutor] a print puzzle

2010-12-02 Thread Richard D. Moores
On Thu, Dec 2, 2010 at 03:13, Alan Gauld wrote: > > "Richard D. Moores" wrote > > s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1] > sum(s) >> >> 0. > > This uses repr() to display the result > > print(sum(s)) >> >> 1.0      Why? > > This uses str() to display the result. > > In ma

Re: [Tutor] a print puzzle

2010-12-02 Thread Alan Gauld
"Richard D. Moores" wrote s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1] sum(s) 0. This uses repr() to display the result print(sum(s)) 1.0 Why? This uses str() to display the result. In many cases str() calls repr() but in other cases str() is a more user friendly format.

[Tutor] a print puzzle

2010-12-02 Thread Richard D. Moores
>>> s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1] >>> sum(s) 0. >>> print(sum(s)) 1.0 Why? >>> f = 0. >>> f**100 0.9889 >>> print(f**100) 1.0 Why? >>> f**1 0.99988898 >>> print(f**1) 0. >>> from math import fsum >>> fsum(s) 1.0