From fa935151d396f8c2285db277871608d1cd61647a Mon Sep 17 00:00:00 2001 From: gorendes <123700346+gorendes@users.noreply.github.com> Date: Sun, 20 Oct 2024 17:19:02 +0300 Subject: [PATCH 1/2] Create functions_niyazi_cetinkaya.py --- Week04/functions_niyazi_cetinkaya.py | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Week04/functions_niyazi_cetinkaya.py diff --git a/Week04/functions_niyazi_cetinkaya.py b/Week04/functions_niyazi_cetinkaya.py new file mode 100644 index 00000000..eb514f2d --- /dev/null +++ b/Week04/functions_niyazi_cetinkaya.py @@ -0,0 +1,36 @@ +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: + """ + Calculate the result of the equation: (x**a + y**b) / c. + + :param x: positional-only integer, default is 0 + :param y: positional-only integer, default is 0 + :param a: positional-or-keyword integer, default is 1 + :param b: positional-or-keyword integer, default is 1 + :param c: keyword-only integer, default is 1 + :return: float result of the equation + """ + return (x**a + y**b) / c + +def fn_w_counter(): + """ + A function that tracks and counts the number of calls, + and records the caller's information. + + :return: Tuple containing total number of calls and a dictionary + with the caller's __name__ as key and the count of calls as value. + """ + if not hasattr(fn_w_counter, "call_count"): + fn_w_counter.call_count = 0 + fn_w_counter.callers = {} + + fn_w_counter.call_count += 1 + caller_name = __name__ + + if caller_name in fn_w_counter.callers: + fn_w_counter.callers[caller_name] += 1 + else: + fn_w_counter.callers[caller_name] = 1 + + return fn_w_counter.call_count, fn_w_counter.callers From 73ca0f6c744284c4b7b4622cd90ea7841d5e1f56 Mon Sep 17 00:00:00 2001 From: gorendes <123700346+gorendes@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:02:56 +0300 Subject: [PATCH 2/2] Update functions_niyazi_cetinkaya.py --- Week04/functions_niyazi_cetinkaya.py | 54 +++++++++++++--------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/Week04/functions_niyazi_cetinkaya.py b/Week04/functions_niyazi_cetinkaya.py index eb514f2d..045a8011 100644 --- a/Week04/functions_niyazi_cetinkaya.py +++ b/Week04/functions_niyazi_cetinkaya.py @@ -1,36 +1,32 @@ -custom_power = lambda x=0, /, e=1: x ** e +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: +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: """ - Calculate the result of the equation: (x**a + y**b) / c. + Calculate a custom equation based on the provided parameters. - :param x: positional-only integer, default is 0 - :param y: positional-only integer, default is 0 - :param a: positional-or-keyword integer, default is 1 - :param b: positional-or-keyword integer, default is 1 - :param c: keyword-only integer, default is 1 - :return: float result of the equation + The function computes the result of the equation: + (x**a + y**b) / c + + :param x: The first integer value (positional-only, default is 0). + :param y: The second integer value (positional-only, default is 0). + :param a: The exponent for x (positional or keyword, default is 1). + :param b: The exponent for y (positional or keyword, default is 1). + :param c: The divisor (keyword-only, default is 1). + :return: The result of the equation as a float. """ return (x**a + y**b) / c -def fn_w_counter(): - """ - A function that tracks and counts the number of calls, - and records the caller's information. - - :return: Tuple containing total number of calls and a dictionary - with the caller's __name__ as key and the count of calls as value. - """ - if not hasattr(fn_w_counter, "call_count"): - fn_w_counter.call_count = 0 - fn_w_counter.callers = {} - - fn_w_counter.call_count += 1 - caller_name = __name__ - - if caller_name in fn_w_counter.callers: - fn_w_counter.callers[caller_name] += 1 +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter, "call_counter"): + fn_w_counter.call_counter = 0 + fn_w_counter.caller_count_dict = {} + + caller = __name__ + fn_w_counter.call_counter += 1 + + if caller not in fn_w_counter.caller_count_dict: + fn_w_counter.caller_count_dict[caller] = 1 else: - fn_w_counter.callers[caller_name] = 1 - - return fn_w_counter.call_count, fn_w_counter.callers + fn_w_counter.caller_count_dict[caller] += 1 + + return fn_w_counter.call_counter, fn_w_counter.caller_count_dict