From 6c92e704982ad3251be89c77eb755337eafdce03 Mon Sep 17 00:00:00 2001 From: RukiyeTura <124088168+RukiyeTura@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:33:11 +0300 Subject: [PATCH 1/2] Create functions_rukiye_tura.py --- Week04/functions_rukiye_tura.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Week04/functions_rukiye_tura.py diff --git a/Week04/functions_rukiye_tura.py b/Week04/functions_rukiye_tura.py new file mode 100644 index 00000000..369b1803 --- /dev/null +++ b/Week04/functions_rukiye_tura.py @@ -0,0 +1,23 @@ +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: + + if c == 0: + raise ValueError("Division by Zero Exception") + + return (x ** a + y ** b) / c + +def fn_w_counter() -> (int, dict[str, int]): + + 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 462796884b5cce8019a84d281982a9ec6ba0395e Mon Sep 17 00:00:00 2001 From: RukiyeTura <124088168+RukiyeTura@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:36:36 +0300 Subject: [PATCH 2/2] Update functions_rukiye_tura.py --- Week04/functions_rukiye_tura.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/Week04/functions_rukiye_tura.py b/Week04/functions_rukiye_tura.py index 369b1803..be5898fe 100644 --- a/Week04/functions_rukiye_tura.py +++ b/Week04/functions_rukiye_tura.py @@ -1,23 +1,19 @@ -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: - if c == 0: - raise ValueError("Division by Zero Exception") +def custom_equation(x: int = 0, y: int = 0,/, a: int = 1, b: int = 1,*, c: int = 1) -> float: - return (x ** a + y ** b) / c + return (x**a + y**b) / c -def fn_w_counter() -> (int, dict[str, int]): - - 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, "counter"): + fn_w_counter.counter = (0, {}) + counter_num = fn_w_counter.counter[0] + counter_dict = fn_w_counter.counter[1] + if __name__ in counter_dict: + counter_dict[__name__] += 1 else: - fn_w_counter.callers[caller_name] = 1 - return fn_w_counter.call_count, fn_w_counter.callers + counter_dict[__name__] = 1 + fn_w_counter.counter = (counter_num + 1, counter_dict) + return fn_w_counter.counter