[Tutor] Tutorial indicating different output

Mark Tolonen metolone+gmane at gmail.com
Fri May 9 07:29:35 CEST 2008


"Eric Morey" <eric at glodime.com> wrote in message 
news:1210279129.5244.23.camel at glodime-XI...
> Hello everyone,
>
> I have no prior experience with programing. I've just started with the
> Python tutorial at http://www.dickbaldwin.com/tocpyth.htm.
> On the section that describes decimal division on this page:
> http://www.dickbaldwin.com/python/Pyth0004.htm
>
> Figure 10 shows:
>
>        >>> 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
>        >>>
>
> I didn't worry too much about it and continued to move on. But I'm
> curious as to why there was a difference. Anyone know why?

http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate

-Mark 




More information about the Tutor mailing list