catch zerodivisionerror python code example

Example: zerodivisionerror python

# Example of a ZeroDivisionError:

number = 43/0
print(number)

"""
You can not divide by zero in Python, otherwise a rather unpleasant and 
hard-to-read message comes up. To prevent this sort of thing from happening,
use the try - except function.
"""

try:
  print(43/0)
except ZeroDivisionError:
  print("Dividing by zero is not allowed!")

"""
This way, Python will print the answer, UNLESS there is a ZeroDivisionError, in
which case Python, instead of printing the error message, will print that you
cannot divide by zero.
"""