#### ZeroDivisionError: float division by zero ¶

By: HagarAbouroumia on Dec. 12, 2021, 6:32 p.m.

What might be the cause of ZeroDivisionError: float division by zero when submitting csv file ?

By: HagarAbouroumia on Dec. 12, 2021, 6:32 p.m.

What might be the cause of ZeroDivisionError: float division by zero when submitting csv file ?

By: warnerjonn on June 16, 2022, 6:14 a.m.

The super class of ZeroDivisionError is ArithmeticError. This exception raised when the second argument of a division or modulo operation is zero. In Mathematics, when a number is divided by a zero, the result is an infinite number. It is impossible to write an Infinite number physically. Python interpreter throws “ZeroDivisionError: division by zero” error if the result is infinite number. While implementing any program logic and there is division operation make sure always handle ArithmeticError or ZeroDivisionError so that program will not terminate.

try:

`z = x / y`

except ZeroDivisionError: z = 0

Or check before you do the division:

if y == 0: z = 0 else: z = x / y

The latter can be reduced to:

z = 0 if y == 0 else (x / y)