[Tutor] ZeroDivisionError: float division

Alan Gauld alan.gauld at btinternet.com
Sun Oct 7 00:28:24 CEST 2007


"pierre cutellic" <pierre.cutellic at gmail.com> wrote

> here is a a piece of code i can't debug:
>
> kx = (neighbor[1]+agent[1])/(dx-(neighbor[1]+agent[1]))
>
> in this line, 'neighbor[1]' and 'agent[1]' are both integers and 
> 'dx' is a
> float so it gives me the following error: 'ZeroDivisionError: float
> division'.

So have you checked that the divisor is not zero?

ie that (dx-(neighbor[1]+agent[1]) is not zero.

That's normally the cause of a ZeroDivisionError.
Without a bit more code or some debug output we
can't really say much more.


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




More information about the Tutor mailing list