Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 395 Bytes

File metadata and controls

33 lines (23 loc) · 395 Bytes

ZeroDivisionError: division by zero

Occurs when attempting to divide a number by zero.

reproduce.py

a = 10
b = 0
print(a / b)

Error message

ZeroDivisionError: division by zero

fix.py

a = 10
b = 0

if b != 0:
    print(a / b)
else:
    print("Cannot divide by zero")

Reflection

Ensure the divisor is not zero before performing division.