You can download this code by clicking the button below.
This code is now available for download.
Define a function that performs division and catches an exception when the divisor is zero, returning an error message in such case.
Technology Stack : Exception handling
Code Type : Mathematical operations and exception handling
Code Difficulty : Intermediate
def aaaa(a, b):
try:
return a / b
except ZeroDivisionError:
return "Cannot divide by zero"