Solution: Add Logging to a Utility Function
Wrap a pure function with a logging decorator that prints input and output, without touching the original logic.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 1–3:
square(n)is a pure utility function that simply returnsn * n. It’s untouched and unaware of logging.Lines 6–13:
withLogging(fn)is a functional decorator. It wraps the original function:Logs the arguments before calling
fn(...). ...