From 1e1ecbb39ee07a79dc2e7e11672a2f2d5233b8c7 Mon Sep 17 00:00:00 2001 From: 1kayraoz <244101021@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 18:49:05 +0300 Subject: [PATCH 1/2] Create functions_kayra_oz.py --- Week04/functions_kayra_oz.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Week04/functions_kayra_oz.py diff --git a/Week04/functions_kayra_oz.py b/Week04/functions_kayra_oz.py new file mode 100644 index 00000000..cc0a85df --- /dev/null +++ b/Week04/functions_kayra_oz.py @@ -0,0 +1,30 @@ +import inspect +from typing import Tuple, Dict + +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: + """ + Computes the custom equation (x**a + y**b) / c. + + :param x: First positional-only base integer. + :param y: Second positional-only base integer. + :param a: First positional-or-keyword exponent integer. + :param b: Second positional-or-keyword exponent integer. + :param c: Keyword-only divisor integer. + :return: The result of the equation as a float. + """ + return float((x**a + y**b) / c) + +def fn_w_counter() -> Tuple[int, Dict[str, int]]: + if not hasattr(fn_w_counter, "caller_counts"): + fn_w_counter.caller_counts = {} + fn_w_counter.total_calls = 0 + + frame = inspect.currentframe().f_back + caller_name = frame.f_globals.get('__name__', 'unknown') + + 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, fn_w_counter.caller_counts) From a62e0a0e196b616663e4e124fd154a960d218107 Mon Sep 17 00:00:00 2001 From: 1kayraoz <244101021@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 18:52:08 +0300 Subject: [PATCH 2/2] Update functions_kayra_oz.py --- Week04/functions_kayra_oz.py | 46 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/Week04/functions_kayra_oz.py b/Week04/functions_kayra_oz.py index cc0a85df..fcbf75dc 100644 --- a/Week04/functions_kayra_oz.py +++ b/Week04/functions_kayra_oz.py @@ -1,30 +1,32 @@ -import inspect -from typing import Tuple, Dict - -custom_power = lambda x=0, /, e=1: x**e +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: """ - Computes the custom equation (x**a + y**b) / c. + Calculates the result of a custom mathematical equation. - :param x: First positional-only base integer. - :param y: Second positional-only base integer. - :param a: First positional-or-keyword exponent integer. - :param b: Second positional-or-keyword exponent integer. - :param c: Keyword-only divisor integer. - :return: The result of the equation as a float. + :param x: The first base (positional-only). + :param y: The second base (positional-only). + :param a: The exponent for the first base (positional-or-keyword). + :param b: The exponent for the second base (positional-or-keyword). + :param c: The divisor (keyword-only). + :return: The result of the equation (x**a + y**b) / c as a float. """ - return float((x**a + y**b) / c) + if type(x) is not int or type(y) is not int or type(a) is not int or type(b) is not int or type(c) is not int: + raise TypeError("All arguments must be integers.") + + return float((x ** a + y ** b) / c) -def fn_w_counter() -> Tuple[int, Dict[str, int]]: - if not hasattr(fn_w_counter, "caller_counts"): - fn_w_counter.caller_counts = {} +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter, "total_calls"): fn_w_counter.total_calls = 0 - - frame = inspect.currentframe().f_back - caller_name = frame.f_globals.get('__name__', 'unknown') - + fn_w_counter.caller_dict = {} + 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, fn_w_counter.caller_counts) + + caller = __name__ + + if caller not in fn_w_counter.caller_dict: + fn_w_counter.caller_dict[caller] = 0 + fn_w_counter.caller_dict[caller] += 1 + + return fn_w_counter.total_calls, fn_w_counter.caller_dict