[Tutor] Assistance with Psuedocode

Alan Gauld alan.gauld at btinternet.com
Thu Nov 18 01:49:36 CET 2010


"Joe Ohmer" <ohmerj1 at mymail.nku.edu> wrote

> The following code works well but I don't understand why
> the mysteryEffect code block changes the picture.
> Doesn’t 64*(r/64) just equal r?

That dependfs on which version of Python you use.
In  earlier versions '/' meant integer division so

(1/64) * 64    => 0 * 64
(120/64) * 64 => 1 * 64
(128/64) * 64 => 2 * 64
(130/64) * 64 => 2 * 64

So only in the case of exact multiples of 64 does it do
what you expect. However, if you have a recent version
of Python (2.6? onwards) '/' means floating point division
so now you get the result you expect (subject to rounding
error)

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list