From 1aa9b022168de1f2a3c29f0a9c976ef4eccf4586 Mon Sep 17 00:00:00 2001 From: sedat Date: Mon, 2 Nov 2026 23:24:10 +0300 Subject: [PATCH 1/4] Add Week 4 HW Added custom_power lambda and custom_equation function for calculations. Implemented fn_w_counter to track function calls. --- Week04/functions_sedat_celik.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Week04/functions_sedat_celik.py diff --git a/Week04/functions_sedat_celik.py b/Week04/functions_sedat_celik.py new file mode 100644 index 00000000..307a0c6b --- /dev/null +++ b/Week04/functions_sedat_celik.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: + """ + Calculates and returns the custom equation + + :param x: first positional-only base value, default is 0 + :type x: int + :param y: second positional-only value, default is 0 + :type y: int + :param a: exponent of x, default is 1 + :type a: int + :param b: exponent of y, default is 1 + :type b: int + :param c: keyword-only divisor value, default is 1 + :type c: int + :return: the calculated result of the equation (x**a + y**b) / c + :rtype: float + """ + + return float((x**a + y**b) / c) + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, "total_calls"): + fn_w_counter.total_calls = 0 + fn_w_counter.caller_counts = {} + + caller = __name__ + + fn_w_counter.total_calls += 1 + fn_w_counter.caller_counts[caller] = ( + fn_w_counter.caller_counts.get(caller, 0) + 1 + ) + + return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts) From d6a9a393bbf6d2592a3461d1c625aa613fd3bcec Mon Sep 17 00:00:00 2001 From: sedat Date: Mon, 2 Nov 2026 23:33:06 +0300 Subject: [PATCH 2/4] Add Week 4 HW --- Week04/functions_sedat_celik.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_sedat_celik.py b/Week04/functions_sedat_celik.py index 307a0c6b..bbbc7961 100644 --- a/Week04/functions_sedat_celik.py +++ b/Week04/functions_sedat_celik.py @@ -21,7 +21,7 @@ def custom_equation(x: int = 0 , y: int = 0 , / , a: int =1 , b: int =1, * , c: return float((x**a + 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, "total_calls"): fn_w_counter.total_calls = 0 fn_w_counter.caller_counts = {} From 75b11230df3faf512fb609f81f7d900b262b16d6 Mon Sep 17 00:00:00 2001 From: sedat Date: Mon, 2 Nov 2026 23:35:06 +0300 Subject: [PATCH 3/4] Add Week 4 HW --- Week04/decorators_sedat_celik | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Week04/decorators_sedat_celik diff --git a/Week04/decorators_sedat_celik b/Week04/decorators_sedat_celik new file mode 100644 index 00000000..ac4ed727 --- /dev/null +++ b/Week04/decorators_sedat_celik @@ -0,0 +1,33 @@ +import time +import tracemalloc +import functools + + +def performance(func): + + @functools.wraps(func) + def wrapper(*args, **kwargs): + + tracemalloc.start() + start_time = time.perf_counter() + start_mem = tracemalloc.get_traced_memory()[0] + + try: + return func(*args, **kwargs) + + finally: + end_time = time.perf_counter() + peak_mem = tracemalloc.get_traced_memory()[1] + + performance.counter += 1 + performance.total_time += end_time - start_time + performance.total_mem += max(peak_mem - start_mem, 0) + + tracemalloc.stop() + + return wrapper + + +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0 From 063d07ef9e6e5cfa5ec6c5b323111a8cece9a0be Mon Sep 17 00:00:00 2001 From: sedat Date: Mon, 2 Nov 2026 23:57:52 +0300 Subject: [PATCH 4/4] Add Week 4 HW --- Week04/{decorators_sedat_celik => decorators_sedat_celik.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Week04/{decorators_sedat_celik => decorators_sedat_celik.py} (100%) diff --git a/Week04/decorators_sedat_celik b/Week04/decorators_sedat_celik.py similarity index 100% rename from Week04/decorators_sedat_celik rename to Week04/decorators_sedat_celik.py