Exercise · Functions as values · lesson 10 of 10
Exercise: the shout decorator
Write a decorator shout(func). It returns a wrapper that calls func with the same positional and keyword arguments it received itself. The wrapper returns the result of func in upper case. In the examples, greet and pair are functions from the tests file: greet(name, greeting="hello") returns f"{greeting}, {name}", and pair(a, b) returns f"{a} and {b}".
shout(greet)("ann")→"HELLO, ANN"shout(pair)("tea", b="jam")→"TEA AND JAM"shout(greet)("bob", greeting="bye")→"BYE, BOB"
Constraints: func always returns a string; it may take no arguments or several, by position and by name.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.