Junior — Senior
Decorator that outputs the function name, its arguments, and the result
livecode
Task condition
It is required to implement a decorator log_execution that, when calling a function, will display its name, the passed positional arguments, and the obtained result.
import functools
def log_execution(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
# TODO: add output of call information
pass
return wrapper
@log_execution
def add_numbers(x, y):
return x + y
# Test the decorator
outcome = add_numbers(3, 5)
print("Result:", outcome)
# Expected output:
# Executing function: add_numbers
# Arguments: (3, 5)
# Result: 8