1. Learn
  2. /
  3. Courses
  4. /
  5. Writing Functions in Python

Exercise

Counter

You're working on a new web app, and you are curious about how many times each of the functions in it gets called. So you decide to write a decorator that adds a counter to each function that you decorate. You could use this information in the future to determine whether there are sections of code that you could remove because they are no longer being used by the app.

Instructions

100 XP
  • Call the function being decorated and return the result.
  • Return the new decorated function.
  • Decorate foo() with the counter() decorator.