From 75463510e0c2f686c5bab424f37f913b78df9b83 Mon Sep 17 00:00:00 2001 From: meryemSayilgan Date: Sun, 8 Nov 2026 22:56:25 +0300 Subject: [PATCH] Implement custom power and equation functions Added custom power and equation functions with type hints and docstrings. --- Week04/functions_meryem_sayilgan.py | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Week04/functions_meryem_sayilgan.py diff --git a/Week04/functions_meryem_sayilgan.py b/Week04/functions_meryem_sayilgan.py new file mode 100644 index 00000000..5e549da0 --- /dev/null +++ b/Week04/functions_meryem_sayilgan.py @@ -0,0 +1,50 @@ +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 + """ + 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) + + +def fn_w_counter() -> (int, dict[str, int]): + """ + This function counts total function calls and tracks calls per caller module. + + :return: The total call count and a dictionary of caller counts. + :rtype: (int, dict[str, int]) + """ + caller = __name__ + + fn_w_counter.total_calls += 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) + + +fn_w_counter.total_calls = 0 +fn_w_counter.caller_counts = {}