From a53938f28c7e166b1f8c37563cdf7f0f697152d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20=C3=87olako=C4=9Flu?= <130840093+mertcolakoglu@users.noreply.github.com> Date: Tue, 7 Apr 2026 22:09:35 +0300 Subject: [PATCH] Add fn_w_counter to track function call statistics --- Week04/functions_mert_colakoglu.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Week04/functions_mert_colakoglu.py diff --git a/Week04/functions_mert_colakoglu.py b/Week04/functions_mert_colakoglu.py new file mode 100644 index 00000000..0caa48d5 --- /dev/null +++ b/Week04/functions_mert_colakoglu.py @@ -0,0 +1,20 @@ +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: + """ + This function calculates a custom equation. + + :param x: first base number (default 0) + :param y: second base number (default 0) + :param a: exponent for x (default 1) + :param b: exponent for y (default 1) + :param c: divisor (default 1) + :return: the result of (x**a + y**b) / c + """ + return (x**a + y**b) / c + +def fn_w_counter() -> (int, dict[str, int]): + fn_w_counter.total_calls = getattr(fn_w_counter, "total_calls", 0) + 1 + callers = getattr(fn_w_counter, "callers", {}) + module_name = fn_w_counter.__module__ + callers[module_name] = callers.get(module_name, 0) + 1 + fn_w_counter.callers = callers + return fn_w_counter.total_calls, fn_w_counter.callers