From 1b6d69241b8bbe0c65b58613cffe214ee599e356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sultan=20Y=C3=BCksel?= Date: Thu, 19 Nov 2026 09:38:43 +0300 Subject: [PATCH 1/4] Implement custom power and equation functions Added custom_power and custom_equation functions along with a counter function. --- Week04/functions_sultan_yuksel.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Week04/functions_sultan_yuksel.py diff --git a/Week04/functions_sultan_yuksel.py b/Week04/functions_sultan_yuksel.py new file mode 100644 index 00000000..b3bc5035 --- /dev/null +++ b/Week04/functions_sultan_yuksel.py @@ -0,0 +1,35 @@ +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 calculates the custom equation (x**a + y**b)/c + + :param x: Positional-only x value, defaults to 0 + :type x: int, optional + :param y: Positional-onlyr y value, defaults to 0 + :type y: int, optional + :param a: Positional-or-keyword exponent for x, defaults to 1 + :type a: int, optional + :param b: Positional-or-keyword exponent for y, defaults to 1 + :type b: int, optional + :param c: Keyword-only division of the sum, defaults to 1 + :type c: int, optional + :return: Result of (x**a + y**b)/c + :rtype: float + + ''' + return (x**a + y**b)/c + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, "counter"): + fn_w_counter.counter = 0 + fn_w_counter.callers = {} + fn_w_counter.counter += 1 + if __name__ in fn_w_counter.callers: + fn_w_counter.callers[__name__] += 1 + else: + fn_w_counter.callers = 1 + return fn_w_counter.counter, fn_w_counter.callers + From 3ca403b3b4f1cf9067d4ed47be0b7b613f45c30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sultan=20Y=C3=BCksel?= Date: Tue, 24 Nov 2026 10:31:37 +0300 Subject: [PATCH 2/4] Fix caller count initialization in fn_w_counter --- Week04/functions_sultan_yuksel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_sultan_yuksel.py b/Week04/functions_sultan_yuksel.py index b3bc5035..05a15941 100644 --- a/Week04/functions_sultan_yuksel.py +++ b/Week04/functions_sultan_yuksel.py @@ -30,6 +30,6 @@ def fn_w_counter() -> tuple[int, dict[str, int]]: if __name__ in fn_w_counter.callers: fn_w_counter.callers[__name__] += 1 else: - fn_w_counter.callers = 1 + fn_w_counter.callers[__name__] = 1 return fn_w_counter.counter, fn_w_counter.callers From 6bfb96d68db21599607105299e2a60ed0f203f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sultan=20Y=C3=BCksel?= Date: Tue, 24 Nov 2026 10:35:39 +0300 Subject: [PATCH 3/4] Create decorators_sultan_yuksel.py --- Week04/decorators_sultan_yuksel.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Week04/decorators_sultan_yuksel.py diff --git a/Week04/decorators_sultan_yuksel.py b/Week04/decorators_sultan_yuksel.py new file mode 100644 index 00000000..54427fbe --- /dev/null +++ b/Week04/decorators_sultan_yuksel.py @@ -0,0 +1,27 @@ +import time +import tracemalloc + + +def performance(f): + if not hasattr(performance, "counter"): + performance.counter = 0 + if not hasattr(performance, "total_time"): + performance.total_time = 0.0 + if not hasattr(performance, "total_mem"): + performance.total_mem = 0 + + def _performance(*args, **kwargs): + performance.counter += 1 + + tracemalloc.start() + start_time = time.time() + + ret = f(*args, **kwargs) + + performance.total_time += time.time() - start_time + performance.total_mem += tracemalloc.get_traced_memory()[1] + tracemalloc.stop() + + return ret + + return _performance From a2bc0200ae4d617f78ce58bca9af18bbb43a3011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sultan=20Y=C3=BCksel?= Date: Tue, 24 Nov 2026 11:01:30 +0300 Subject: [PATCH 4/4] Update functions_sultan_yuksel.py --- Week04/functions_sultan_yuksel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_sultan_yuksel.py b/Week04/functions_sultan_yuksel.py index 05a15941..1e719997 100644 --- a/Week04/functions_sultan_yuksel.py +++ b/Week04/functions_sultan_yuksel.py @@ -22,7 +22,7 @@ def custom_equation (x: int = 0, y: int = 0, / , a: int = 1, b: int = 1, * , c: return (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, "counter"): fn_w_counter.counter = 0 fn_w_counter.callers = {}