From 2a1d2b8badded2eb456575c81bd01524496b352b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gamze=20K=C4=B1l=C4=B1n=C3=A7?= <149265010+gamzeklnc@users.noreply.github.com> Date: Mon, 5 Jan 2026 13:42:13 +0300 Subject: [PATCH] Add function to count calls with caller information Implements a function to count calls and track callers. --- Week04/fn_w_counter_gamze_kilinc.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Week04/fn_w_counter_gamze_kilinc.py diff --git a/Week04/fn_w_counter_gamze_kilinc.py b/Week04/fn_w_counter_gamze_kilinc.py new file mode 100644 index 00000000..fe22eeff --- /dev/null +++ b/Week04/fn_w_counter_gamze_kilinc.py @@ -0,0 +1,17 @@ +def fn_w_counter() -> tuple[int, dict[str, int]]: + """ + Counts function calls with caller information. + + :return: A tuple containing total call count and a dictionary + mapping caller names to their call counts. + """ + if not hasattr(fn_w_counter, "_total_calls"): + fn_w_counter._total_calls = 0 + fn_w_counter._callers = {} + + caller = __name__ + + fn_w_counter._total_calls += 1 + fn_w_counter._callers[caller] = fn_w_counter._callers.get(caller, 0) + 1 + + return fn_w_counter._total_calls, fn_w_counter._callers