From 8beab93b919b358d0470add08e9b07045717ed5d Mon Sep 17 00:00:00 2001 From: protagonist9 Date: Tue, 3 Mar 2026 16:56:03 +0300 Subject: [PATCH 1/6] Week03 homeworks --- Week03/... | 52 ++++++++++++++++++++++++++++++++ Week03/pyramid_tarik_bozgan.py | 6 ++++ Week03/sequences_tarik_bozgan.py | 23 ++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 Week03/... create mode 100644 Week03/pyramid_tarik_bozgan.py create mode 100644 Week03/sequences_tarik_bozgan.py diff --git a/Week03/... b/Week03/... new file mode 100644 index 00000000..2c8c6f25 --- /dev/null +++ b/Week03/... @@ -0,0 +1,52 @@ +import os + + +files = [f for f in os.listdir(os.path.dirname(__file__)) if f.startswith("pyramid")] +for f in files: + exec("import " + f[:-3] + " as " + f[:-3]) + print(f"The module {f[:-3]} has been imported.") + + +def test_names(): + for f in files: + assert "calculate_pyramid_height" in dir(eval(f[:-3])), ( + "calculate_pyramid_height is not defined in " + f[:-3] + ) + + +def test_types(): + for f in files: + assert callable(eval(f[:-3]).calculate_pyramid_height), ( + "calculate_pyramid_height is not callable in " + f[:-3] + ) + assert isinstance(eval(f[:-3]).calculate_pyramid_height(1), int), ( + "calculate_pyramid_height is not returning an int in " + f[:-3] + ) + + +def test_calculate_pyramid_height(): + for f in files: + assert eval(f[:-3]).calculate_pyramid_height(1) == 1, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) + assert eval(f[:-3]).calculate_pyramid_height(2) == 1, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) + assert eval(f[:-3]).calculate_pyramid_height(6) == 3, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) + assert eval(f[:-3]).calculate_pyramid_height(20) == 5, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) + assert eval(f[:-3]).calculate_pyramid_height(100) == 13, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) + assert eval(f[:-3]).calculate_pyramid_height(1000) == 44, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) + assert eval(f[:-3]).calculate_pyramid_height(10000) == 140, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) + assert eval(f[:-3]).calculate_pyramid_height(100000) == 446, ( + "calculate_pyramid_height is not working in " + f[:-3] + ) diff --git a/Week03/pyramid_tarik_bozgan.py b/Week03/pyramid_tarik_bozgan.py new file mode 100644 index 00000000..a742a203 --- /dev/null +++ b/Week03/pyramid_tarik_bozgan.py @@ -0,0 +1,6 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + while(number_of_blocks >= 0): + height += 1 + number_of_blocks -= height + return height - 1 \ No newline at end of file diff --git a/Week03/sequences_tarik_bozgan.py b/Week03/sequences_tarik_bozgan.py new file mode 100644 index 00000000..1ba02067 --- /dev/null +++ b/Week03/sequences_tarik_bozgan.py @@ -0,0 +1,23 @@ +def remove_duplicates(seq): + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq): + counts = {} + for item in seq: + if item in counts: + counts[item] += 1 + else: + counts[item] = 1 + return counts + + +def reverse_dict(d): + reversed_dict = {} + for key, value in d.items(): + reversed_dict[value] = key + return reversed_dict \ No newline at end of file From c8ba2290a4924e167396a175cdb26157e6f440b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tar=C4=B1k=20Boz=C4=9Fan?= <156001177+protagonist9@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:58:25 +0300 Subject: [PATCH 2/6] Create decorators_tarik_bozgan.py --- Week04/decorators_tarik_bozgan.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week04/decorators_tarik_bozgan.py diff --git a/Week04/decorators_tarik_bozgan.py b/Week04/decorators_tarik_bozgan.py new file mode 100644 index 00000000..718e0a3b --- /dev/null +++ b/Week04/decorators_tarik_bozgan.py @@ -0,0 +1,26 @@ +import time +import tracemalloc + +def performance(func): + def wrapper(*args, **kwargs): + tracemalloc.start() + t1 = time.perf_counter() + + result = func(*args, **kwargs) + + t2 = time.perf_counter() + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + # Hata buradaydı: Sayaçları wrapper'a değil, performance fonksiyonuna ekliyoruz + performance.counter += 1 + performance.total_time += (t2 - t1) + performance.total_mem += peak + + return result + return wrapper + +# Testin beklediği özellikler (Attributes) ana fonksiyona atanmalı +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 From ff6b594e8e805f170b17db59ce4719b0fcb48fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tar=C4=B1k=20Boz=C4=9Fan?= <156001177+protagonist9@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:03:03 +0300 Subject: [PATCH 3/6] Delete Week04/decorators_tarik_bozgan.py --- Week04/decorators_tarik_bozgan.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 Week04/decorators_tarik_bozgan.py diff --git a/Week04/decorators_tarik_bozgan.py b/Week04/decorators_tarik_bozgan.py deleted file mode 100644 index 718e0a3b..00000000 --- a/Week04/decorators_tarik_bozgan.py +++ /dev/null @@ -1,26 +0,0 @@ -import time -import tracemalloc - -def performance(func): - def wrapper(*args, **kwargs): - tracemalloc.start() - t1 = time.perf_counter() - - result = func(*args, **kwargs) - - t2 = time.perf_counter() - _, peak = tracemalloc.get_traced_memory() - tracemalloc.stop() - - # Hata buradaydı: Sayaçları wrapper'a değil, performance fonksiyonuna ekliyoruz - performance.counter += 1 - performance.total_time += (t2 - t1) - performance.total_mem += peak - - return result - return wrapper - -# Testin beklediği özellikler (Attributes) ana fonksiyona atanmalı -performance.counter = 0 -performance.total_time = 0 -performance.total_mem = 0 From d27774d885be7bdd9683dc57d5984b7b6854608d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tar=C4=B1k=20Boz=C4=9Fan?= <156001177+protagonist9@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:04:36 +0300 Subject: [PATCH 4/6] Created decorators_tarik_bozgan.py Implement a performance decorator to track execution time and memory usage. --- Week04/decorators_tarik_bozgan.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week04/decorators_tarik_bozgan.py diff --git a/Week04/decorators_tarik_bozgan.py b/Week04/decorators_tarik_bozgan.py new file mode 100644 index 00000000..718e0a3b --- /dev/null +++ b/Week04/decorators_tarik_bozgan.py @@ -0,0 +1,26 @@ +import time +import tracemalloc + +def performance(func): + def wrapper(*args, **kwargs): + tracemalloc.start() + t1 = time.perf_counter() + + result = func(*args, **kwargs) + + t2 = time.perf_counter() + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + # Hata buradaydı: Sayaçları wrapper'a değil, performance fonksiyonuna ekliyoruz + performance.counter += 1 + performance.total_time += (t2 - t1) + performance.total_mem += peak + + return result + return wrapper + +# Testin beklediği özellikler (Attributes) ana fonksiyona atanmalı +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 From 2a65109c1eb0ef1edf666735df373764f4a45ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tar=C4=B1k=20Boz=C4=9Fan?= <156001177+protagonist9@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:07:24 +0300 Subject: [PATCH 5/6] Created functions_tarik_bozgan.py Added custom power function and custom equation function with type checks. --- Week04/functions_tarik_bozgan.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week04/functions_tarik_bozgan.py diff --git a/Week04/functions_tarik_bozgan.py b/Week04/functions_tarik_bozgan.py new file mode 100644 index 00000000..60492966 --- /dev/null +++ b/Week04/functions_tarik_bozgan.py @@ -0,0 +1,24 @@ +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: + """ + :param x: + :param y: + :param a: + :param b: + :param c: + :return: + """ + if not isinstance(x, int): raise TypeError("x must be int") + if not isinstance(y, int): raise TypeError("y must be int") + if not isinstance(a, int): raise TypeError("a must be int") + if not isinstance(b, int): raise TypeError("b must be int") + if not isinstance(c, int): raise TypeError("c must be int") + + return float((x ** a + y ** b) / c) + +_count = 0 +def fn_w_counter() -> (int, dict[str, int]): + global _count + _count += 1 + return _count, {__name__: _count} From 9fa8034d5c52c1dbd2e31105785a713b574acceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tar=C4=B1k=20Boz=C4=9Fan?= <156001177+protagonist9@users.noreply.github.com> Date: Sat, 21 Mar 2026 00:36:08 +0300 Subject: [PATCH 6/6] Delete Week03/... --- Week03/... | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 Week03/... diff --git a/Week03/... b/Week03/... deleted file mode 100644 index 2c8c6f25..00000000 --- a/Week03/... +++ /dev/null @@ -1,52 +0,0 @@ -import os - - -files = [f for f in os.listdir(os.path.dirname(__file__)) if f.startswith("pyramid")] -for f in files: - exec("import " + f[:-3] + " as " + f[:-3]) - print(f"The module {f[:-3]} has been imported.") - - -def test_names(): - for f in files: - assert "calculate_pyramid_height" in dir(eval(f[:-3])), ( - "calculate_pyramid_height is not defined in " + f[:-3] - ) - - -def test_types(): - for f in files: - assert callable(eval(f[:-3]).calculate_pyramid_height), ( - "calculate_pyramid_height is not callable in " + f[:-3] - ) - assert isinstance(eval(f[:-3]).calculate_pyramid_height(1), int), ( - "calculate_pyramid_height is not returning an int in " + f[:-3] - ) - - -def test_calculate_pyramid_height(): - for f in files: - assert eval(f[:-3]).calculate_pyramid_height(1) == 1, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(2) == 1, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(6) == 3, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(20) == 5, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(100) == 13, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(1000) == 44, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(10000) == 140, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(100000) == 446, ( - "calculate_pyramid_height is not working in " + f[:-3] - )