try catch zero division error python code example
Example 1: divide by zero error python exception handling
try:
print 1/0
except ZeroDivisionError:
print "You can't divide by zero!"
Example 2: handling zero division error in python
x = 0
try:
answer = 1/x
except ZeroDivisionError:
answer = 'undefined'
print('The answer is {result}'.format(result=answer)