Function for Basic Arithmetic Operations

  • Share this:

Code introduction


The function takes three arguments and generates a dictionary containing the results of all operations using these arguments through internally defined addition, subtraction, multiplication, and division operations.


Technology Stack : Built-in functions (def, if, return), operators (+, -, *, /)

Code Type : Function

Code Difficulty : Intermediate


                
                    
def aaaa(arg1, arg2, arg3):
    def _add(a, b):
        return a + b

    def _sub(a, b):
        return a - b

    def _mul(a, b):
        return a * b

    def _div(a, b):
        return a / b if b != 0 else 'Error: Division by zero'

    results = {
        'add': _add(arg1, arg2),
        'sub': _sub(arg1, arg3),
        'mul': _mul(arg1, arg3),
        'div': _div(arg2, arg3)
    }
    return results