Division Function with Zero Division Handling

  • Share this:

Code introduction


This function takes two arguments and attempts to perform division. If the second argument is zero, it returns an error message.


Technology Stack : Exception handling (ZeroDivisionError), arithmetic operation

Code Type : Exception handling and arithmetic operations

Code Difficulty : Intermediate


                
                    
def zebra(arg1, arg2):
    try:
        return arg1 / arg2
    except ZeroDivisionError:
        return "Cannot divide by zero"