From 0ca3a36584f685493dc8a69e98904113a3eb813e Mon Sep 17 00:00:00 2001 From: MertYksl03 Date: Sun, 29 Mar 2026 19:30:27 +0300 Subject: [PATCH 1/3] Add decorators_mert_yuksel.py and functions_mert_yuksel.py --- Week04/decorators_mert_yuksel.py | 31 +++++++++++++++++++++++++++++++ Week04/functions_mert_yuksel.py | 26 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Week04/decorators_mert_yuksel.py create mode 100644 Week04/functions_mert_yuksel.py diff --git a/Week04/decorators_mert_yuksel.py b/Week04/decorators_mert_yuksel.py new file mode 100644 index 00000000..4c2a6a03 --- /dev/null +++ b/Week04/decorators_mert_yuksel.py @@ -0,0 +1,31 @@ +import time +import tracemalloc as tm + +def performance(func): + """ + A decorater function that measures the performance of the given function and also save some statistics + (The definition is from lecture notes.pdf) + """ + performance.counter = 0 + performance.total_mem = 0.0 + performance.total_time = 0.0 + + + def _performance(*args, **kwargs): + tm.start() + start_time = time.time() + + result = func(*args, **kwargs) + + _, peak_mem = tm.get_traced_memory() + endtime = time.time() + + tm.stop() + + performance.total_time += endtime - start_time + performance.total_mem += peak_mem + performance.counter += 1 + + return result + + return _performance \ No newline at end of file diff --git a/Week04/functions_mert_yuksel.py b/Week04/functions_mert_yuksel.py new file mode 100644 index 00000000..b2abcf85 --- /dev/null +++ b/Week04/functions_mert_yuksel.py @@ -0,0 +1,26 @@ +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 does something + + :param x: positional only argument, defaults to 0 + :type x: int + :param y: poisitonal only argument, defaults to 0 + :type y: int + :param a: positional or keyword argument, defaults to 1 + :type a: int + :param b: positional or keyword argument, defaults to 1 + :type b: int + :param c: keyword only argument, defaults to 1 + :type c: int + :return: the result of division by c the sum of x to the power of a and y to the power of b + :rtype : float + """ + return (x**a + y **b) / c + +_count = 0 +def fn_w_counter() -> (int, dict[str, int]): + global _count + _count += 1 + return _count, {__name__: _count} \ No newline at end of file From 5a21719d0bd14e38fa7727578aef06116582e98e Mon Sep 17 00:00:00 2001 From: MertYksl03 Date: Mon, 30 Mar 2026 18:22:13 +0300 Subject: [PATCH 2/3] Add awaitme_mert_yuksel.py --- Week05/awaitme_mert_yuksel.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Week05/awaitme_mert_yuksel.py diff --git a/Week05/awaitme_mert_yuksel.py b/Week05/awaitme_mert_yuksel.py new file mode 100644 index 00000000..a4774153 --- /dev/null +++ b/Week05/awaitme_mert_yuksel.py @@ -0,0 +1,7 @@ +def awaitme(func): + + async def _awaitme(*args, **kwargs): + result = func(*args, **kwargs) + return result + + return _awaitme \ No newline at end of file From 4e43d58f082f69f7c7ef772bf1fd7710db975da0 Mon Sep 17 00:00:00 2001 From: MertYksl03 Date: Wed, 1 Apr 2026 21:34:32 +0300 Subject: [PATCH 3/3] made the asked changes --- Week04/functions_mert_yuksel.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Week04/functions_mert_yuksel.py b/Week04/functions_mert_yuksel.py index b2abcf85..2d0eb829 100644 --- a/Week04/functions_mert_yuksel.py +++ b/Week04/functions_mert_yuksel.py @@ -19,8 +19,9 @@ def custom_equation(x: int=0, y: int=0, /, a: int=1, b: int=1, *, c: int=1) -> f """ return (x**a + y **b) / c -_count = 0 def fn_w_counter() -> (int, dict[str, int]): - global _count - _count += 1 - return _count, {__name__: _count} \ No newline at end of file + if not hasattr(fn_w_counter, "count"): + fn_w_counter.count = 0 + + fn_w_counter.count += 1 + return fn_w_counter.count, {__name__: fn_w_counter.count} \ No newline at end of file