From 9cd7eed3b0fc4bca4121eb3ff33f418f48af9ad3 Mon Sep 17 00:00:00 2001 From: ArdaDenizKinikli Date: Mon, 30 Mar 2026 17:08:42 +0300 Subject: [PATCH 1/4] Create: decorators_ardadeniz_kinikli.py --- Week04/decorators_ardadeniz_kinikli.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Week04/decorators_ardadeniz_kinikli.py diff --git a/Week04/decorators_ardadeniz_kinikli.py b/Week04/decorators_ardadeniz_kinikli.py new file mode 100644 index 00000000..3d7c1fc2 --- /dev/null +++ b/Week04/decorators_ardadeniz_kinikli.py @@ -0,0 +1,25 @@ +import time +import tracemalloc +def performance(func): + if not hasattr(performance,"counter"): + setattr(performance,"counter",0) + + if not hasattr(performance,"total_time"): + setattr(performance,"total_time",0) + + if not hasattr(performance,"total_mem"): + setattr(performance,"total_mem",0) + + def _d1(*args,**kwargs): + tracemalloc.start() + start_time = time.perf_counter() + result = func(*args,**kwargs) + end_time = time.perf_counter() + elapsed = end_time - start_time + current_mem, peak_mem = tracemalloc.get_traced_memory() + performance.counter += 1 + performance.total_time += elapsed + performance.total_mem += peak_mem + return result + return _d1 + From d2f2a8d67a54ecb3c26e01b08cbd02fb277ede29 Mon Sep 17 00:00:00 2001 From: ArdaDenizKinikli Date: Mon, 30 Mar 2026 17:10:00 +0300 Subject: [PATCH 2/4] Create: functions_ardadeniz_kinikli.py --- Week04/functions_ardadeniz_kinikli.py | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Week04/functions_ardadeniz_kinikli.py diff --git a/Week04/functions_ardadeniz_kinikli.py b/Week04/functions_ardadeniz_kinikli.py new file mode 100644 index 00000000..f61ca764 --- /dev/null +++ b/Week04/functions_ardadeniz_kinikli.py @@ -0,0 +1,38 @@ +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 computes the result of the expression (x**a + y**b) / c. + + :param x: The base for the first exponentiation. Positional-only. + :type x: int + :param y: The base for the second exponentiation. Positional-only. + :type y: int + :param a: The exponent for x. Positional-or-keyword. + :type a: int + :param b: The exponent for y. Positional-or-keyword. + :type b: int + :param c: The divisor. Keyword-only. Defaults to 1. + :type c: int + :returns: The result of the calculation. + :rtype: float + + """ + return (custom_power(x,a) + custom_power(y,b))/c + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, "count"): + setattr(fn_w_counter, "count", 0) + fn_w_counter.count += 1 + temp_dict = {} + temp_dict[(str)(__name__)] = fn_w_counter.count + temp_tuple = (fn_w_counter.count, temp_dict) + return temp_tuple + +if __name__ == "__main__": + print(custom_power(2,3)) + print(custom_power(2,e=3)) + print(custom_equation(2, 2, a=3, b=3,c=1)) + for i in range(5): + fn_w_counter() + print(fn_w_counter()) \ No newline at end of file From e91dd8605ddbbbaae522606584fe78a7e127ab04 Mon Sep 17 00:00:00 2001 From: ArdaDenizKinikli Date: Tue, 31 Mar 2026 15:29:35 +0300 Subject: [PATCH 3/4] Remove: Print calls from functions_ardadeniz_kinikli --- Week04/functions_ardadeniz_kinikli.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Week04/functions_ardadeniz_kinikli.py b/Week04/functions_ardadeniz_kinikli.py index f61ca764..f014584d 100644 --- a/Week04/functions_ardadeniz_kinikli.py +++ b/Week04/functions_ardadeniz_kinikli.py @@ -28,11 +28,3 @@ def fn_w_counter() -> tuple[int, dict[str, int]]: temp_dict[(str)(__name__)] = fn_w_counter.count temp_tuple = (fn_w_counter.count, temp_dict) return temp_tuple - -if __name__ == "__main__": - print(custom_power(2,3)) - print(custom_power(2,e=3)) - print(custom_equation(2, 2, a=3, b=3,c=1)) - for i in range(5): - fn_w_counter() - print(fn_w_counter()) \ No newline at end of file From 99172642e87e06ddefe6c365832764bf8316423c Mon Sep 17 00:00:00 2001 From: ArdaDenizKinikli Date: Tue, 31 Mar 2026 15:46:27 +0300 Subject: [PATCH 4/4] Fix: Test.py requirements --- Week04/functions_ardadeniz_kinikli.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Week04/functions_ardadeniz_kinikli.py b/Week04/functions_ardadeniz_kinikli.py index f014584d..175ef012 100644 --- a/Week04/functions_ardadeniz_kinikli.py +++ b/Week04/functions_ardadeniz_kinikli.py @@ -20,11 +20,12 @@ def custom_equation(x: int = 0, y: int= 0, /, a: int=1, b: int=1, *, c: int=1) - """ return (custom_power(x,a) + custom_power(y,b))/c -def fn_w_counter() -> tuple[int, dict[str, int]]: +def fn_w_counter() -> (int, dict[str, int]): if not hasattr(fn_w_counter, "count"): setattr(fn_w_counter, "count", 0) + setattr(fn_w_counter,"dictionary",{}) fn_w_counter.count += 1 - temp_dict = {} - temp_dict[(str)(__name__)] = fn_w_counter.count - temp_tuple = (fn_w_counter.count, temp_dict) - return temp_tuple + fn_w_counter.dictionary[(str)(__name__)] = fn_w_counter.count + return fn_w_counter.count,fn_w_counter.dictionary + +