Solution 1

def pretty_result(original_function):
    def wrapped(a, b):
        original_result = original_function(a, b)
        function_name = original_function.__name__
        return "The result of the function '{}' is: {}".format(
            function_name, original_result)
    return wrapped

Pretty Results Decorator

Implement a @pretty_result decorator that changes the result of any function, returning the result plus a pretty message. Example, the function sum(1, 2) should return 3. If applied @pretty_result it should return "The result of the function 'sum' is: 3".

Test Cases

test subtract function - Run Test

def test_subtract_function():

    @pretty_result
    def subtract(x, y):
        return x - y

    assert subtract(13, 8) == "The result of the function 'subtract' is: 5"

test add function - Run Test

def test_add_function():
    @pretty_result
    def add(x, y):
        return x + y

    assert add(2, 5) == "The result of the function 'add' is: 7"
def pretty_result(original_function): pass # This is for your testing purposes # Uncomment and "Run Code": # ======================================== # @pretty_result # def add(x, y): # return x + y # print(add(2, 5)) # ======================================== # Do you see: "The result of the function 'add' is: 7" ??