From f2103b2f1df372bee5bc9ab5a9002ac36f1c6ce6 Mon Sep 17 00:00:00 2001 From: GulsumCey1an Date: Fri, 6 Nov 2026 01:35:48 +0300 Subject: [PATCH 1/3] Add custom_equation and fn_w_counter functions Implement custom equation and function call counter --- Week04/functions_gulsum_ceylan.py | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Week04/functions_gulsum_ceylan.py diff --git a/Week04/functions_gulsum_ceylan.py b/Week04/functions_gulsum_ceylan.py new file mode 100644 index 00000000..4ebc815b --- /dev/null +++ b/Week04/functions_gulsum_ceylan.py @@ -0,0 +1,38 @@ + +import inspect + +custom_power = lambda x=0, /, e=1: x ** e + + +def custom_equation( + x: int = 0, + y: int = 0, + /, + a: int = 1, + b: int = 1, + *, + c: int = 1 +) -> float: + """ + Calculate the result of a custom equation. + + :param x: First integer. + :param y: Second integer. + :param a: Exponent of x. + :param b: Exponent of y. + :param c: Divisor. + :return: Result of the equation. + """ + return (x ** a + y ** b) / c + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + caller = inspect.currentframe().f_back.f_globals["__name__"] + + if not hasattr(fn_w_counter, "counts"): + fn_w_counter.counts = {} + + counts = fn_w_counter.counts + counts[caller] = counts.get(caller, 0) + 1 + + return sum(counts.values()), counts.copy() From dc2ac5e875862c6c86459e3b173796cb0c793a77 Mon Sep 17 00:00:00 2001 From: GulsumCey1an Date: Fri, 6 Nov 2026 01:40:25 +0300 Subject: [PATCH 2/3] Fix type hint for fn_w_counter return value --- Week04/functions_gulsum_ceylan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_gulsum_ceylan.py b/Week04/functions_gulsum_ceylan.py index 4ebc815b..276f4fa4 100644 --- a/Week04/functions_gulsum_ceylan.py +++ b/Week04/functions_gulsum_ceylan.py @@ -26,7 +26,7 @@ def custom_equation( return (x ** a + y ** b) / c -def fn_w_counter() -> tuple[int, dict[str, int]]: +def fn_w_counter() -> (int, dict[str, int]): caller = inspect.currentframe().f_back.f_globals["__name__"] if not hasattr(fn_w_counter, "counts"): From d428bee332bf0e5d682e580ef7980ef35ddf0c72 Mon Sep 17 00:00:00 2001 From: GulsumCey1an Date: Fri, 6 Nov 2026 01:49:27 +0300 Subject: [PATCH 3/3] Refactor custom_equation docstring and fn_w_counter Updated docstring for custom_equation and modified fn_w_counter to track total calls and calls by module. --- Week04/functions_gulsum_ceylan.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Week04/functions_gulsum_ceylan.py b/Week04/functions_gulsum_ceylan.py index 276f4fa4..00d76d95 100644 --- a/Week04/functions_gulsum_ceylan.py +++ b/Week04/functions_gulsum_ceylan.py @@ -1,6 +1,4 @@ -import inspect - custom_power = lambda x=0, /, e=1: x ** e @@ -14,25 +12,30 @@ def custom_equation( c: int = 1 ) -> float: """ - Calculate the result of a custom equation. + Calculate a mathematical equation. :param x: First integer. :param y: Second integer. - :param a: Exponent of x. - :param b: Exponent of y. + :param a: Exponent for x. + :param b: Exponent for y. :param c: Divisor. - :return: Result of the equation. + :return: Calculated result. """ return (x ** a + y ** b) / c +total_calls = 0 +calls_by_module = {} + + def fn_w_counter() -> (int, dict[str, int]): - caller = inspect.currentframe().f_back.f_globals["__name__"] + global total_calls - if not hasattr(fn_w_counter, "counts"): - fn_w_counter.counts = {} + total_calls += 1 + module_name = __name__ - counts = fn_w_counter.counts - counts[caller] = counts.get(caller, 0) + 1 + calls_by_module[module_name] = ( + calls_by_module.get(module_name, 0) + 1 + ) - return sum(counts.values()), counts.copy() + return total_calls, calls_by_module.copy()