Build a Logging Decorator
Hard
Write a decorator called log_call that prints "Calling <function_name>" before the decorated function runs, and "Finished <function_name>" after it returns. Apply it to a function greet(name) that returns f"Hello, {name}!".
Input
No direct input — call the decorated greet("Alice").
Output
Printed log messages plus the function's return value.
Example
Input
greet("Alice")
Output
Calling greet Finished greet Hello, Alice!
A decorator is a function that takes a function and returns a wrapper function. Use func.__name__ to get the function's name, and make sure the wrapper returns the original function's result.
20 XP on solve
Back to lesson
Your Solution
Output
Click "Run" to execute your code...
⏳ Loading Python runtime (first run may take a few seconds)...
Log in to submit your solution and earn XP.