From d419690e548be2d1c2fa0e0cf4a635a54eb20c03 Mon Sep 17 00:00:00 2001 From: aysegulyildizz <139223718+aysegulyildizz@users.noreply.github.com> Date: Tue, 23 Dec 2025 11:51:42 +0300 Subject: [PATCH] Add functions for custom power and equation with counter This file contains a custom power function, a custom equation function with parameter validation, and a function that counts calls to it. --- Week04/functions_aysegul_yildiz.py | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Week04/functions_aysegul_yildiz.py diff --git a/Week04/functions_aysegul_yildiz.py b/Week04/functions_aysegul_yildiz.py new file mode 100644 index 00000000..8fccbbd2 --- /dev/null +++ b/Week04/functions_aysegul_yildiz.py @@ -0,0 +1,48 @@ +import inspect + + +# custom_power +custom_power = lambda x=0, /, e=1: x**e + + +# custom_equation +def custom_equation( + x: int = 0, + y: int = 0, + /, + a: int = 1, + b: int = 1, + *, + c: int = 1, +) -> float: + """ + Calculate a custom equation. + :param x: positional-only integer + :param y: positional-only integer + :param a: positional-or-keyword integer + :param b: positional-or-keyword integer + :param c: keyword-only integer + :return: result of the equation + """ + + for name, value in {"x": x, "y": y, "a": a, "b": b, "c": c}.items(): + if not isinstance(value, int): + raise TypeError(f"{name} must be int") + + return (x**a + y**b) / c + + +# fn_w_counter +_counter = 0 +_callers = {} + + +def fn_w_counter() -> (int, dict[str, int]): + global _counter # ✅ sadece bu global gerekli + + _counter += 1 + + module_name = inspect.getmodule(fn_w_counter).__name__ + _callers[module_name] = _callers.get(module_name, 0) + 1 + + return _counter, {module_name: _callers[module_name]}