Stacked Decorators Run Bottom-Up

Medium ⏱ 12 min 60% acceptance ★★★★★ 4.9
Write exclaim(func) (appends '!' to the result) and upper(func) (uppercases it). Apply BOTH to a greet() returning 'hi' so the result is 'HI!' — which requires knowing that the decorator closest to the function applies first. Get the stacking order right.

Examples

Example 1
Input
greet()
Output
'HI!'
Explanation

upper ran on the raw result first, then exclaim appended.

Constraints

  • Both decorators + correct stack order.
  • Result must be exactly 'HI!'.

Topics

Decoratorsstacking order

Companies

GoogleMetaAdobe

Hints

Hint 1

@exclaim above @upper (upper is closer, runs first).

Hint 2

Trace: exclaim(upper(greet)).

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.