Skip to content
C

Call Counter Decorator

Mediumpython

Write a decorator @count_calls that tracks and prints how many times the function it wraps has been called, then apply it to a function that greets someone.

Why not a timing decorator? measuring and printing actual elapsed time produces a different number on every run, so it can never be checked by an automated judge against one exact expected output. Counting calls tests exactly the same decorator mechanics (wrapping, args/*kwargs, calling the original function, returning its result) in a way that's fully deterministic.

Approach: the decorator keeps a counter in its enclosing scope (a closure), increments it and prints a message on every call, then calls through to the original function.

Input: Two lines: how many times to call the function, then the name to greet.

Output: For each call: a Call <n> to greet line, followed by the greeting itself.

Input (stdin)

Output

Run your code to see output here...