Divide function (was: Re: [Tutor] wxPython? (fwd))

Jim Angstadt jimajima9@yahoo.com
Mon, 31 Dec 2001 10:50:42 -0800 (PST)


Just a newbie thought:

The results below seem consistent with 
integer division using a 'floor' approach.

--- Danny Yoo <dyoo@hkn.eecs.berkeley.edu> wrote:

<snip>

> from Numeric import *
> 
> def divide(x,y):
>     return x/y
> 
> for y in range(-10,10,1):
>     x=2
>     try:
>         print divide(x,y), y
>         
>     except ZeroDivisionError:
>         print "You are trying to divide by zero"
>     
> ----------------
> 
> -1 -10
> -1 -9
> -1 -8
> -1 -7
> -1 -6
> -1 -5
> -1 -4
> -1 -3
> -1 -2
> -2 -1
> You are trying to divide by zero
> 2 1
> 1 2
> 0 3
> 0 4
> 0 5
> 0 6
> 0 7
> 0 8
> 0 9
> ------------------------------
> Why x/y gives wrong results?

<snip> 


=====
Regards,
Jim

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com