zerodivisionerror python

Solutions on MaxInterview for zerodivisionerror python by the best coders in the world

showing results for - "zerodivisionerror python"
Selene
15 Feb 2019
1# Example of a ZeroDivisionError:
2
3number = 43/0
4print(number)
5
6"""
7You can not divide by zero in Python, otherwise a rather unpleasant and 
8hard-to-read message comes up. To prevent this sort of thing from happening,
9use the try - except function.
10"""
11
12try:
13  print(43/0)
14except ZeroDivisionError:
15  print("Dividing by zero is not allowed!")
16
17"""
18This way, Python will print the answer, UNLESS there is a ZeroDivisionError, in
19which case Python, instead of printing the error message, will print that you
20cannot divide by zero.
21"""