From 204cdfa2a22e43d2e02a8d0b3a1a8304f17378c8 Mon Sep 17 00:00:00 2001 From: Onur Konuk <95957528+onurkonukk@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:22:50 +0300 Subject: [PATCH] Create functions_onur_konuk.py --- Week04/functions_onur_konuk.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Week04/functions_onur_konuk.py diff --git a/Week04/functions_onur_konuk.py b/Week04/functions_onur_konuk.py new file mode 100644 index 00000000..6cd91ee6 --- /dev/null +++ b/Week04/functions_onur_konuk.py @@ -0,0 +1,39 @@ +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 the value of the equation (x**a + y**b) / c. + + :param x: Positional-only base value for the first term; defaults to 0. + :param y: Positional-only base value for the second term; defaults to 0. + :param a: Exponent for x; defaults to 1. + :param b: Exponent for y; defaults to 1. + :param c: Keyword-only divisor for the equation; defaults to 1. + :return: Result of the equation as a float. + :rtype: float + :raises ZeroDivisionError: if c is 0. + """ + if c == 0: + raise ZeroDivisionError("Division by zero is not allowed.") + return (x**a + y**b) / c + +def fn_w_counter() -> (int, dict[str, int]): + """ + Counts the number of times it has been called and tracks the caller. + + :return: Tuple containing total call count and a dictionary with caller info. + :rtype: tuple + """ + if not hasattr(fn_w_counter, "call_count"): + fn_w_counter.call_count = 0 + fn_w_counter.callers_dict = {} + + fn_w_counter.call_count += 1 + caller = __name__ + + if caller in fn_w_counter.callers_dict: + fn_w_counter.callers_dict[caller] += 1 + else: + fn_w_counter.callers_dict[caller] = 1 + + return fn_w_counter.call_count, fn_w_counter.callers_dict