From 1596d1a1a87aee4a673f324041dc3906d1e682bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Feyza=20=C3=96zdemir?= Date: Sat, 31 Oct 2026 13:16:03 +0300 Subject: [PATCH 1/3] Add Week04 functions assignment - Feyza --- Week04/functions_feyza_ozdemir.py | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Week04/functions_feyza_ozdemir.py diff --git a/Week04/functions_feyza_ozdemir.py b/Week04/functions_feyza_ozdemir.py new file mode 100644 index 00000000..c6f5d4c0 --- /dev/null +++ b/Week04/functions_feyza_ozdemir.py @@ -0,0 +1,51 @@ +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: + """ + This function calculates the result of a custom mathematical equation. + + :param x: The first base value (positional-only), defaults to 0. + :type x: int + :param y: The second base value (positional-only), defaults to 0. + :type y: int + :param a: The first exponent (positional-or-keyword), defaults to 1. + :type a: int + :param b: The second exponent (positional-or-keyword), defaults to 1. + :type b: int + :param c: The divisor (keyword-only), defaults to 1. + :type c: int + :return: The result of (x**a + y**b) / c as a float. + :rtype: float + """ + return float((x ** a + y ** b) / c) + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + """ + This function counts total function calls and tracks calls per caller module. + + :return: A tuple containing the total call count and a dictionary of caller counts. + :rtype: tuple[int, dict[str, int]] + """ + caller_frame = inspect.currentframe().f_back + caller_name = caller_frame.f_globals.get("__name__", "__main__") if caller_frame else "__main__" + + fn_w_counter.total_calls += 1 + fn_w_counter.caller_counts[caller_name] = fn_w_counter.caller_counts.get(caller_name, 0) + 1 + + return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts) + + +fn_w_counter.total_calls = 0 +fn_w_counter.caller_counts = {} \ No newline at end of file From 6d3db0ebeb3da90661d175bb9f9b054bf6051625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Feyza=20=C3=96zdemir?= Date: Sat, 31 Oct 2026 13:25:39 +0300 Subject: [PATCH 2/3] Update fn_w_counter signature and docstring - Feyza --- Week04/functions_feyza_ozdemir.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Week04/functions_feyza_ozdemir.py b/Week04/functions_feyza_ozdemir.py index c6f5d4c0..4abc165f 100644 --- a/Week04/functions_feyza_ozdemir.py +++ b/Week04/functions_feyza_ozdemir.py @@ -31,12 +31,12 @@ def custom_equation( return float((x ** a + y ** b) / c) -def fn_w_counter() -> tuple[int, dict[str, int]]: +def fn_w_counter() -> (int, dict[str, int]): """ This function counts total function calls and tracks calls per caller module. - :return: A tuple containing the total call count and a dictionary of caller counts. - :rtype: tuple[int, dict[str, int]] + :return: The total call count and a dictionary of caller counts. + :rtype: (int, dict[str, int]) """ caller_frame = inspect.currentframe().f_back caller_name = caller_frame.f_globals.get("__name__", "__main__") if caller_frame else "__main__" From 1c849ec0914ca23fb28010b5e060af48f860013e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Feyza=20=C3=96zdemir?= Date: Sat, 31 Oct 2026 13:45:16 +0300 Subject: [PATCH 3/3] Fix fn_w_counter caller logic and remove unused import - Feyza --- Week04/functions_feyza_ozdemir.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Week04/functions_feyza_ozdemir.py b/Week04/functions_feyza_ozdemir.py index 4abc165f..9bea792b 100644 --- a/Week04/functions_feyza_ozdemir.py +++ b/Week04/functions_feyza_ozdemir.py @@ -1,5 +1,3 @@ -import inspect - custom_power = lambda x=0, /, e=1: x ** e @@ -28,6 +26,9 @@ def custom_equation( :return: The result of (x**a + y**b) / c as a float. :rtype: float """ + if not (type(x) is int and type(y) is int and type(a) is int and type(b) is int and type(c) is int): + raise TypeError("All parameters must be integers.") + return float((x ** a + y ** b) / c) @@ -38,11 +39,10 @@ def fn_w_counter() -> (int, dict[str, int]): :return: The total call count and a dictionary of caller counts. :rtype: (int, dict[str, int]) """ - caller_frame = inspect.currentframe().f_back - caller_name = caller_frame.f_globals.get("__name__", "__main__") if caller_frame else "__main__" + caller = __name__ fn_w_counter.total_calls += 1 - fn_w_counter.caller_counts[caller_name] = fn_w_counter.caller_counts.get(caller_name, 0) + 1 + fn_w_counter.caller_counts[caller] = fn_w_counter.caller_counts.get(caller, 0) + 1 return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts)