#57MediumFunctions· Decorators
Function Decorators: Call Logger
Input format
`calls`: a list of `[function_name, a, b]` entries, where `function_name` is `"divide"` or `"power"`.
Output format
The log as a list of strings.
Examples
Input: calls = [["divide",7,2],["power",2,10]]
Output: ["divide(7, 2) -> 3","power(2, 10) -> 1024","decorated: divide, power"]
Both calls succeed and are logged with their results.
Input: calls = [["divide",1,0]]
Output: ["divide(1, 0) raised ZeroDivisionError","decorated: divide, power"]
Integer division by zero raises ZeroDivisionError; the wrapper logs it and re-raises, and `run_logged` ignores it.
Constraints
- 0 <= len(calls) <= 20
- -100 <= a, b <= 100
- power is only called with 0 <= b <= 10
Study first
- #python
- #decorators
- #higher-order-functions
- #functools
