"Eric Morey" <[EMAIL PROTECTED]> wrote


       >>> 2.0/5 # get decimal quotient
       0.4
       >>> 2/5.0 # do it again
       0.4
       >>>

http://www.dickbaldwin.com/python/Pyth0004-fig10.htm


Howerver, using the python shell in my terminal, I get:
       >>> 2.0/5 # get decimal quotient
       0.40000000000000002
       >>> 2/5.0 # do it again
       0.40000000000000002
       >>>

Looks like the author cheated a little.
If you explicitly print the result:

>>> print 2.0/5 # get decimal quotient
0.4

It should work as expected.

Without the print Python uses a slightly different set of
formatting rules for values. (print uses str() while evaluating
uses repr(), but you don;t need to worry about that yet! :-)

My advice to beginners is to always use print for consistent
results even though it is more typing.

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to