Python ZeroDivisionError: meaning and fix

ZeroDivisionError: You divided by zero.

Code that causes it

total = 10
count = 0
print(total / count)
Open in the runner

The divisor is a variable that held 0. You averaged an empty list.

Check with if that the divisor is not 0 before you divide.

How to fix it

total = 10
count = 0
if count != 0:
    print(total / count)
Open in the runner

Why it happens

Dividing by zero has no answer. Python does not invent one. It stops.

The official docs are in English. See it in the official Python docs

Back to the runnerMore errors