ZeroDivisionError: float division

(pierre_cu) #1

Hi,
i’m actually stuck with a stupid syntax problem.

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’.

And it is the same if i convert them into floats by float() function.

0 Likes

(forTe) #2

The problem is that you are trying to divide by zero: i.e.

3/0, 10/0, 100/0, etc.

This is not a defined mathematical capability (in all math, not just your computer) so it throws an error.

In your code it results when dx = neighbor[1] + agent[1] (when dx- (neigbor[1] +agent[1]) = 0).

Its not an error with types (int vs. float)

0 Likes

(pierre_cu) #3

Thanks for that, i believed that it was a problem of float conversion:no:

i will be able to post a wip soon

thanks again

0 Likes