From d37a9724f8c05d4cd4ce3e2232afbbd5a329bea7 Mon Sep 17 00:00:00 2001 From: busedemirbass Date: Tue, 24 Mar 2026 20:32:38 +0300 Subject: [PATCH 1/2] Implement custom equation function and call counter Adds a custom equation function with parameter rules and a call counter. --- Week04/functions_buse_demirbas.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Week04/functions_buse_demirbas.py diff --git a/Week04/functions_buse_demirbas.py b/Week04/functions_buse_demirbas.py new file mode 100644 index 00000000..3587e46d --- /dev/null +++ b/Week04/functions_buse_demirbas.py @@ -0,0 +1,27 @@ +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: + """ + Calculates (x**a + y**b) / c with specific parameter rules. + + :param x: Positional-only base x + :param y: Positional-only base y + :param a: Positional-or-keyword exponent a + :param b: Positional-or-keyword exponent b + :param c: Keyword-only divisor c + :return: The result of the equation as float + """ + if not all(isinstance(i, int) for i in [x, y, a, b, c]): + raise TypeError("All parameters must be integers") + + return float((x**a + y**b) / c) + +custom_power = lambda x=0, /, e=1: x**e + +_counter = 0 +_call_map = {} + +def fn_w_counter() -> tuple[int, dict[str, int]]: + global _counter + _counter += 1 + module_name = __name__.split('.')[-1] + _call_map[module_name] = _counter + return _counter, _call_map From 4f1cac5edf80bb8f5d5d958745e084ec19cbd415 Mon Sep 17 00:00:00 2001 From: busedemirbass Date: Tue, 24 Mar 2026 20:34:57 +0300 Subject: [PATCH 2/2] Update functions_buse_demirbas.py --- Week04/functions_buse_demirbas.py | 41 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Week04/functions_buse_demirbas.py b/Week04/functions_buse_demirbas.py index 3587e46d..b967ae25 100644 --- a/Week04/functions_buse_demirbas.py +++ b/Week04/functions_buse_demirbas.py @@ -1,27 +1,28 @@ +import sys + +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 (x**a + y**b) / c with specific parameter rules. - - :param x: Positional-only base x - :param y: Positional-only base y - :param a: Positional-or-keyword exponent a - :param b: Positional-or-keyword exponent b - :param c: Keyword-only divisor c - :return: The result of the equation as float + Calculates (x**a + y**b) / c. + :param x: base x + :param y: base y + :param a: exp a + :param b: exp b + :param c: div c + :return: float result """ - if not all(isinstance(i, int) for i in [x, y, a, b, c]): - raise TypeError("All parameters must be integers") - - return float((x**a + y**b) / c) -custom_power = lambda x=0, /, e=1: x**e + if not all(isinstance(v, int) for v in (x, y, a, b, c)): + raise TypeError("Arguments must be integers") + return float((x**a + y**b) / c) -_counter = 0 -_call_map = {} def fn_w_counter() -> tuple[int, dict[str, int]]: - global _counter - _counter += 1 - module_name = __name__.split('.')[-1] - _call_map[module_name] = _counter - return _counter, _call_map + + if not hasattr(fn_w_counter, "count"): + fn_w_counter.count = 0 + + fn_w_counter.count += 1 + module_name = __name__.split('.')[-1] + return fn_w_counter.count, {module_name: fn_w_counter.count}