from functools import wraps
def log_calls(func):
@wraps(func)
def wrapper(*args, **kwargs):
parts = [repr(a) for a in args] + [f"{k}={v!r}" for k, v in kwargs.items()]
result = func(*args, **kwargs)
print(f"{func.__name__}({', '.join(parts)}) -> {result!r}")
return result
return wrapper
@log_calls
def ticket_price(base, seats=1, member=False):
return base * seats * (0.9 if member else 1)
ticket_price(250)
ticket_price(250, 3, member=True)
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!