Re: Strange behavior of int()

2006-01-29 Thread Dan Bishop
Brian wrote: > Hello, > > Can someone tell me what I am doing wrong in this code. > > If I create a file change.py with the following contents: > > def intTest(M, c): > r = M > for k in c: > print 'int(r/k) = ', int(r/k), 'r =', r, 'k =', k, 'r/k > =', r/k >

Re: Strange behavior of int()

2006-01-29 Thread Rob E
> Why is int(r/k), where r = 0.5 and k = 0.5 = 0? Shouldn't it be 1? > And why is the last one = 4 and not 5? I dont' know why the differences in your exact case. However, please realise that Regardless of the programming language good programming practice is to never rely on the int of a float

Re: Strange behavior of int()

2006-01-26 Thread Dan Sommers
On 26 Jan 2006 18:42:34 -0800, "Brian" <[EMAIL PROTECTED]> wrote: > If I execute a similar command from the command line, it works just > fine: int(0.05/0.05) > 1 Try this: >>> print 2.3 - int(2.3/.25)*.25 0.05 >>> 2.3 - int(2.3/.25)*.25 0.049822 Then check out

Strange behavior of int()

2006-01-26 Thread Brian
Hello, Can someone tell me what I am doing wrong in this code. If I create a file change.py with the following contents: def intTest(M, c): r = M for k in c: print 'int(r/k) = ', int(r/k), 'r =', r, 'k =', k, 'r/k =', r/k r = r - (k*int(r/k)) intT