From c3c2189e21fabbeba40c5b27a3e12953a0b57db3 Mon Sep 17 00:00:00 2001 From: efesarigul Date: Thu, 2 Apr 2026 22:28:46 +0300 Subject: [PATCH 1/3] Add custom mathematical functions and counter --- Week04/functions_efesamil_sarigul.py | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Week04/functions_efesamil_sarigul.py diff --git a/Week04/functions_efesamil_sarigul.py b/Week04/functions_efesamil_sarigul.py new file mode 100644 index 00000000..b571ec23 --- /dev/null +++ b/Week04/functions_efesamil_sarigul.py @@ -0,0 +1,35 @@ +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: + """ + Calculates the mathematical equation. + + :param x: The first base value. + :type x: int + :param y: The second base value. + :type y: int + :param a: The exponent for x. + :type a: int + :param b: The exponent for y. + :type b: int + :param c: The divisor. + :type c: int + :return: The result of the equation. + :rtype: float + """ + return float((x**a + y**b) / c) + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, "count"): + fn_w_counter.count = 0 + fn_w_counter.caller_info = {} + + fn_w_counter.count += 1 + + caller_name = inspect.currentframe().f_back.f_globals.get('__name__', '__main__') + + fn_w_counter.caller_info[caller_name] = fn_w_counter.caller_info.get(caller_name, 0) + 1 + + return fn_w_counter.count, fn_w_counter.caller_info From c285fadbb9d401000f9464e8bff2f63c7a37c607 Mon Sep 17 00:00:00 2001 From: efesarigul Date: Thu, 2 Apr 2026 22:31:12 +0300 Subject: [PATCH 2/3] Fix return type annotation for fn_w_counter --- Week04/functions_efesamil_sarigul.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Week04/functions_efesamil_sarigul.py b/Week04/functions_efesamil_sarigul.py index b571ec23..30e293a9 100644 --- a/Week04/functions_efesamil_sarigul.py +++ b/Week04/functions_efesamil_sarigul.py @@ -21,7 +21,7 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int """ return float((x**a + y**b) / c) -def fn_w_counter() -> tuple[int, dict[str, int]]: +def fn_w_counter() -> (int, dict[str, int]): if not hasattr(fn_w_counter, "count"): fn_w_counter.count = 0 fn_w_counter.caller_info = {} @@ -33,3 +33,11 @@ def fn_w_counter() -> tuple[int, dict[str, int]]: fn_w_counter.caller_info[caller_name] = fn_w_counter.caller_info.get(caller_name, 0) + 1 return fn_w_counter.count, fn_w_counter.caller_info + + fn_w_counter.count += 1 + + caller_name = inspect.currentframe().f_back.f_globals.get('__name__', '__main__') + + fn_w_counter.caller_info[caller_name] = fn_w_counter.caller_info.get(caller_name, 0) + 1 + + return fn_w_counter.count, fn_w_counter.caller_info From 49fbb9262ab0537dd0af57b960c51bf7cb4a8815 Mon Sep 17 00:00:00 2001 From: efesarigul Date: Thu, 2 Apr 2026 22:35:06 +0300 Subject: [PATCH 3/3] Refactor function_w_counter for cleaner caller name Refactor caller name retrieval and remove unused imports. --- Week04/functions_efesamil_sarigul.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Week04/functions_efesamil_sarigul.py b/Week04/functions_efesamil_sarigul.py index 30e293a9..a757962b 100644 --- a/Week04/functions_efesamil_sarigul.py +++ b/Week04/functions_efesamil_sarigul.py @@ -1,5 +1,3 @@ -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: @@ -28,15 +26,8 @@ def fn_w_counter() -> (int, dict[str, int]): fn_w_counter.count += 1 - caller_name = inspect.currentframe().f_back.f_globals.get('__name__', '__main__') - - fn_w_counter.caller_info[caller_name] = fn_w_counter.caller_info.get(caller_name, 0) + 1 - - return fn_w_counter.count, fn_w_counter.caller_info - - fn_w_counter.count += 1 - caller_name = inspect.currentframe().f_back.f_globals.get('__name__', '__main__') + caller_name = __name__.split('.')[-1] fn_w_counter.caller_info[caller_name] = fn_w_counter.caller_info.get(caller_name, 0) + 1