From 28d75d32cd760389747ab7f940c3631e7a117416 Mon Sep 17 00:00:00 2001 From: Kerem Kurtuldu <200315061@ogr.cbu.edu.tr> Date: Mon, 6 Jan 2025 22:35:06 +0300 Subject: [PATCH] Create functions_kerem_kurtuldu.py --- Week04/functions_kerem_kurtuldu.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week04/functions_kerem_kurtuldu.py diff --git a/Week04/functions_kerem_kurtuldu.py b/Week04/functions_kerem_kurtuldu.py new file mode 100644 index 00000000..ff196acc --- /dev/null +++ b/Week04/functions_kerem_kurtuldu.py @@ -0,0 +1,26 @@ +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: + """ + Compute a custom equation. + :param x: Positional-only base for the first term (default: 0) + :param y: Positional-only base for the second term (default: 0) + :param a: Exponent for the first term (default: 1) + :param b: Exponent for the second term (default: 1) + :param c: Divisor, keyword-only (default: 1) + :return: Result of the calculation as a float + """ + return (x**a + y**b) / c + +def fn_w_counter() -> tuple[int, dict]: + """ + Function that tracks how many times it has been called and logs calls by module name. + :return: A tuple containing the call count and a dictionary of module call statistics. + """ + if not hasattr(fn_w_counter, "counter"): + fn_w_counter.counter = 0 + fn_w_counter.dict = {} + caller_name = __name__ + fn_w_counter.counter += 1 + fn_w_counter.dict[caller_name] = fn_w_counter.dict.get(caller_name, 0) + 1 + return fn_w_counter.counter, fn_w_counter.dict