From a2544ae4e3e79783bd145ca39d9a1a92cad86904 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 00:05:47 +0300 Subject: [PATCH 01/12] 2 , 3 , 4 weeks hw --- Week02/types_hilmican_karadag.py | 4 ++ Week03/pyramid_hilmican_karadag.py | 11 +++++ Week03/sequences_hilmican_karadag.py | 26 ++++++++++++ Week04/decorators_hilmican_karadag.py | 58 +++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 Week02/types_hilmican_karadag.py create mode 100644 Week03/pyramid_hilmican_karadag.py create mode 100644 Week03/sequences_hilmican_karadag.py create mode 100644 Week04/decorators_hilmican_karadag.py diff --git a/Week02/types_hilmican_karadag.py b/Week02/types_hilmican_karadag.py new file mode 100644 index 000000000..2241fa306 --- /dev/null +++ b/Week02/types_hilmican_karadag.py @@ -0,0 +1,4 @@ +my_int = 10 +my_float = 3.14 +my_bool = True +my_complex = 3 + 9j \ No newline at end of file diff --git a/Week03/pyramid_hilmican_karadag.py b/Week03/pyramid_hilmican_karadag.py new file mode 100644 index 000000000..2a6fe2ffb --- /dev/null +++ b/Week03/pyramid_hilmican_karadag.py @@ -0,0 +1,11 @@ +def calculate_pyramid_height(number_of_blocks): + + height = 1 + + while number_of_blocks >= x: + + number_of_blocks = number_of_blocks - x + + height = height + 1 + + return height \ No newline at end of file diff --git a/Week03/sequences_hilmican_karadag.py b/Week03/sequences_hilmican_karadag.py new file mode 100644 index 000000000..13d3168bf --- /dev/null +++ b/Week03/sequences_hilmican_karadag.py @@ -0,0 +1,26 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + return {value: key for key, value in d.items()} \ No newline at end of file diff --git a/Week04/decorators_hilmican_karadag.py b/Week04/decorators_hilmican_karadag.py new file mode 100644 index 000000000..9d4514b8e --- /dev/null +++ b/Week04/decorators_hilmican_karadag.py @@ -0,0 +1,58 @@ +import functools +import time +import tracemalloc + + +def performance(fn): + """ + Decorator that measures execution time and memory of the wrapped function. + + Statistics are stored as attributes on the decorator itself: + + - ``performance.counter``: number of decorated-function calls + - ``performance.total_time``: total time spent in seconds + - ``performance.total_mem``: total memory consumed in bytes + + :param fn: the function to decorate + :type fn: callable + :return: the wrapped function + :rtype: callable + """ + + @functools.wraps(fn) + def wrapper(*args, **kwargs): + started_here = not tracemalloc.is_tracing() + if started_here: + tracemalloc.start() + tracemalloc.reset_peak() + mem_before = tracemalloc.get_traced_memory()[0] + start = time.perf_counter() + + try: + return fn(*args, **kwargs) + finally: + elapsed = time.perf_counter() - start + peak = tracemalloc.get_traced_memory()[1] + if started_here: + tracemalloc.stop() + performance.counter += 1 + performance.total_time += elapsed + performance.total_mem += max(peak - mem_before, 0) + + return wrapper + + +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0 + + +if __name__ == "__main__": + + @performance + def build_list(n: int) -> list[int]: + return [i * i for i in range(n)] + + build_list(100_000) + build_list(50_000) + print(performance.counter, performance.total_time, performance.total_mem) From 8d43dc849e116850c967baa3885e5f853085bb81 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 00:11:56 +0300 Subject: [PATCH 02/12] changing --- Week03/pyramid_hilmican_karadag.py | 11 ----- Week03/sequences_hilmican_karadag.py | 26 ------------ Week04/decorators_hilmican_karadag.py | 58 --------------------------- 3 files changed, 95 deletions(-) delete mode 100644 Week03/pyramid_hilmican_karadag.py delete mode 100644 Week03/sequences_hilmican_karadag.py delete mode 100644 Week04/decorators_hilmican_karadag.py diff --git a/Week03/pyramid_hilmican_karadag.py b/Week03/pyramid_hilmican_karadag.py deleted file mode 100644 index 2a6fe2ffb..000000000 --- a/Week03/pyramid_hilmican_karadag.py +++ /dev/null @@ -1,11 +0,0 @@ -def calculate_pyramid_height(number_of_blocks): - - height = 1 - - while number_of_blocks >= x: - - number_of_blocks = number_of_blocks - x - - height = height + 1 - - return height \ No newline at end of file diff --git a/Week03/sequences_hilmican_karadag.py b/Week03/sequences_hilmican_karadag.py deleted file mode 100644 index 13d3168bf..000000000 --- a/Week03/sequences_hilmican_karadag.py +++ /dev/null @@ -1,26 +0,0 @@ -def remove_duplicates(seq: list) -> list: - """ - This function removes duplicates from a list. - """ - result = [] - for item in seq: - if item not in result: - result.append(item) - return result - - -def list_counts(seq: list) -> dict: - """ - This function counts the number of occurrences of each item in a list. - """ - counts = {} - for item in seq: - counts[item] = counts.get(item, 0) + 1 - return counts - - -def reverse_dict(d: dict) -> dict: - """ - This function reverses the keys and values of a dictionary. - """ - return {value: key for key, value in d.items()} \ No newline at end of file diff --git a/Week04/decorators_hilmican_karadag.py b/Week04/decorators_hilmican_karadag.py deleted file mode 100644 index 9d4514b8e..000000000 --- a/Week04/decorators_hilmican_karadag.py +++ /dev/null @@ -1,58 +0,0 @@ -import functools -import time -import tracemalloc - - -def performance(fn): - """ - Decorator that measures execution time and memory of the wrapped function. - - Statistics are stored as attributes on the decorator itself: - - - ``performance.counter``: number of decorated-function calls - - ``performance.total_time``: total time spent in seconds - - ``performance.total_mem``: total memory consumed in bytes - - :param fn: the function to decorate - :type fn: callable - :return: the wrapped function - :rtype: callable - """ - - @functools.wraps(fn) - def wrapper(*args, **kwargs): - started_here = not tracemalloc.is_tracing() - if started_here: - tracemalloc.start() - tracemalloc.reset_peak() - mem_before = tracemalloc.get_traced_memory()[0] - start = time.perf_counter() - - try: - return fn(*args, **kwargs) - finally: - elapsed = time.perf_counter() - start - peak = tracemalloc.get_traced_memory()[1] - if started_here: - tracemalloc.stop() - performance.counter += 1 - performance.total_time += elapsed - performance.total_mem += max(peak - mem_before, 0) - - return wrapper - - -performance.counter = 0 -performance.total_time = 0.0 -performance.total_mem = 0 - - -if __name__ == "__main__": - - @performance - def build_list(n: int) -> list[int]: - return [i * i for i in range(n)] - - build_list(100_000) - build_list(50_000) - print(performance.counter, performance.total_time, performance.total_mem) From 87036331939e7150d35bfc3e159a3b4e22f88cf3 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 00:18:38 +0300 Subject: [PATCH 03/12] week 3 hw --- Week03/pyramid_hilmican_karadag.py | 11 +++++++++++ Week03/sequences_hilmican_karadag.py | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Week03/pyramid_hilmican_karadag.py create mode 100644 Week03/sequences_hilmican_karadag.py diff --git a/Week03/pyramid_hilmican_karadag.py b/Week03/pyramid_hilmican_karadag.py new file mode 100644 index 000000000..2a6fe2ffb --- /dev/null +++ b/Week03/pyramid_hilmican_karadag.py @@ -0,0 +1,11 @@ +def calculate_pyramid_height(number_of_blocks): + + height = 1 + + while number_of_blocks >= x: + + number_of_blocks = number_of_blocks - x + + height = height + 1 + + return height \ No newline at end of file diff --git a/Week03/sequences_hilmican_karadag.py b/Week03/sequences_hilmican_karadag.py new file mode 100644 index 000000000..13d3168bf --- /dev/null +++ b/Week03/sequences_hilmican_karadag.py @@ -0,0 +1,26 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + return {value: key for key, value in d.items()} \ No newline at end of file From e004984527ae3eef29dfe57716da3b4f1739987b Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 14:22:23 +0300 Subject: [PATCH 04/12] deleted --- Week02/types_hilmican_karadag.py | 4 ---- Week03/pyramid_hilmican_karadag.py | 11 ----------- Week03/sequences_hilmican_karadag.py | 26 -------------------------- 3 files changed, 41 deletions(-) delete mode 100644 Week02/types_hilmican_karadag.py delete mode 100644 Week03/pyramid_hilmican_karadag.py delete mode 100644 Week03/sequences_hilmican_karadag.py diff --git a/Week02/types_hilmican_karadag.py b/Week02/types_hilmican_karadag.py deleted file mode 100644 index 2241fa306..000000000 --- a/Week02/types_hilmican_karadag.py +++ /dev/null @@ -1,4 +0,0 @@ -my_int = 10 -my_float = 3.14 -my_bool = True -my_complex = 3 + 9j \ No newline at end of file diff --git a/Week03/pyramid_hilmican_karadag.py b/Week03/pyramid_hilmican_karadag.py deleted file mode 100644 index 2a6fe2ffb..000000000 --- a/Week03/pyramid_hilmican_karadag.py +++ /dev/null @@ -1,11 +0,0 @@ -def calculate_pyramid_height(number_of_blocks): - - height = 1 - - while number_of_blocks >= x: - - number_of_blocks = number_of_blocks - x - - height = height + 1 - - return height \ No newline at end of file diff --git a/Week03/sequences_hilmican_karadag.py b/Week03/sequences_hilmican_karadag.py deleted file mode 100644 index 13d3168bf..000000000 --- a/Week03/sequences_hilmican_karadag.py +++ /dev/null @@ -1,26 +0,0 @@ -def remove_duplicates(seq: list) -> list: - """ - This function removes duplicates from a list. - """ - result = [] - for item in seq: - if item not in result: - result.append(item) - return result - - -def list_counts(seq: list) -> dict: - """ - This function counts the number of occurrences of each item in a list. - """ - counts = {} - for item in seq: - counts[item] = counts.get(item, 0) + 1 - return counts - - -def reverse_dict(d: dict) -> dict: - """ - This function reverses the keys and values of a dictionary. - """ - return {value: key for key, value in d.items()} \ No newline at end of file From 622a66007da0baec7bd4bad3cdbb69a85dbbe655 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 14:25:34 +0300 Subject: [PATCH 05/12] week 2 hw types --- Week02/types_hilmican_karadag.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Week02/types_hilmican_karadag.py diff --git a/Week02/types_hilmican_karadag.py b/Week02/types_hilmican_karadag.py new file mode 100644 index 000000000..2241fa306 --- /dev/null +++ b/Week02/types_hilmican_karadag.py @@ -0,0 +1,4 @@ +my_int = 10 +my_float = 3.14 +my_bool = True +my_complex = 3 + 9j \ No newline at end of file From b5c200e9513d0e577a91942ff1afe8d0e6edb7e6 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 14:37:43 +0300 Subject: [PATCH 06/12] week 3 hw pyramid --- Week03/pyramid_hilmican_karadag.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Week03/pyramid_hilmican_karadag.py diff --git a/Week03/pyramid_hilmican_karadag.py b/Week03/pyramid_hilmican_karadag.py new file mode 100644 index 000000000..2a6fe2ffb --- /dev/null +++ b/Week03/pyramid_hilmican_karadag.py @@ -0,0 +1,11 @@ +def calculate_pyramid_height(number_of_blocks): + + height = 1 + + while number_of_blocks >= x: + + number_of_blocks = number_of_blocks - x + + height = height + 1 + + return height \ No newline at end of file From 9bb2650017e92fedcf34792c6ab2d3326f759815 Mon Sep 17 00:00:00 2001 From: hilmican karadag <121621092+hilmicankaradag@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:42:24 +0300 Subject: [PATCH 07/12] Update pyramid_hilmican_karadag.py --- Week03/pyramid_hilmican_karadag.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Week03/pyramid_hilmican_karadag.py b/Week03/pyramid_hilmican_karadag.py index 2a6fe2ffb..f51e6c626 100644 --- a/Week03/pyramid_hilmican_karadag.py +++ b/Week03/pyramid_hilmican_karadag.py @@ -2,10 +2,10 @@ def calculate_pyramid_height(number_of_blocks): height = 1 - while number_of_blocks >= x: + while number_of_blocks >= height: - number_of_blocks = number_of_blocks - x + number_of_blocks = number_of_blocks - height height = height + 1 - return height \ No newline at end of file + return height From f4b4f724613717313d17f7887f5586ab0864ad1a Mon Sep 17 00:00:00 2001 From: hilmican karadag <121621092+hilmicankaradag@users.noreply.github.com> Date: Wed, 14 Oct 2026 16:00:55 +0300 Subject: [PATCH 08/12] Update pyramid_hilmican_karadag.py --- Week03/pyramid_hilmican_karadag.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Week03/pyramid_hilmican_karadag.py b/Week03/pyramid_hilmican_karadag.py index f51e6c626..ac844f9b0 100644 --- a/Week03/pyramid_hilmican_karadag.py +++ b/Week03/pyramid_hilmican_karadag.py @@ -1,11 +1,10 @@ def calculate_pyramid_height(number_of_blocks): + height = 0 + blocks_needed = 1 - height = 1 - - while number_of_blocks >= height: - - number_of_blocks = number_of_blocks - height - - height = height + 1 + while number_of_blocks >= blocks_needed: + number_of_blocks -= blocks_needed + height += 1 + blocks_needed += 1 return height From 6179d9e4d17ac1ce57bbe61342ef1e781d9d10dd Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 16:02:29 +0300 Subject: [PATCH 09/12] week 3 hw sequances --- Week03/sequences_hilmican_karadag.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week03/sequences_hilmican_karadag.py diff --git a/Week03/sequences_hilmican_karadag.py b/Week03/sequences_hilmican_karadag.py new file mode 100644 index 000000000..13d3168bf --- /dev/null +++ b/Week03/sequences_hilmican_karadag.py @@ -0,0 +1,26 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + return {value: key for key, value in d.items()} \ No newline at end of file From 414409dc8a791510f7a1d1db1d72d98d09e22dc7 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 16:05:12 +0300 Subject: [PATCH 10/12] Delete sequences_hilmican_karadag.py --- Week03/sequences_hilmican_karadag.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 Week03/sequences_hilmican_karadag.py diff --git a/Week03/sequences_hilmican_karadag.py b/Week03/sequences_hilmican_karadag.py deleted file mode 100644 index 13d3168bf..000000000 --- a/Week03/sequences_hilmican_karadag.py +++ /dev/null @@ -1,26 +0,0 @@ -def remove_duplicates(seq: list) -> list: - """ - This function removes duplicates from a list. - """ - result = [] - for item in seq: - if item not in result: - result.append(item) - return result - - -def list_counts(seq: list) -> dict: - """ - This function counts the number of occurrences of each item in a list. - """ - counts = {} - for item in seq: - counts[item] = counts.get(item, 0) + 1 - return counts - - -def reverse_dict(d: dict) -> dict: - """ - This function reverses the keys and values of a dictionary. - """ - return {value: key for key, value in d.items()} \ No newline at end of file From 4112cc8f7367561d1cc3f726b1d708f389ecfd87 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 16:06:20 +0300 Subject: [PATCH 11/12] week 3 hw sequences --- Week03/sequences_hilmican_karadag.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week03/sequences_hilmican_karadag.py diff --git a/Week03/sequences_hilmican_karadag.py b/Week03/sequences_hilmican_karadag.py new file mode 100644 index 000000000..13d3168bf --- /dev/null +++ b/Week03/sequences_hilmican_karadag.py @@ -0,0 +1,26 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + return {value: key for key, value in d.items()} \ No newline at end of file From 4c6bb5ce3f3db1dd5756248f5e42cae1e131d266 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 14 Oct 2026 16:07:47 +0300 Subject: [PATCH 12/12] week 4 hw decorator --- Week04/decorators_hilmican_karadag.py | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Week04/decorators_hilmican_karadag.py diff --git a/Week04/decorators_hilmican_karadag.py b/Week04/decorators_hilmican_karadag.py new file mode 100644 index 000000000..9d4514b8e --- /dev/null +++ b/Week04/decorators_hilmican_karadag.py @@ -0,0 +1,58 @@ +import functools +import time +import tracemalloc + + +def performance(fn): + """ + Decorator that measures execution time and memory of the wrapped function. + + Statistics are stored as attributes on the decorator itself: + + - ``performance.counter``: number of decorated-function calls + - ``performance.total_time``: total time spent in seconds + - ``performance.total_mem``: total memory consumed in bytes + + :param fn: the function to decorate + :type fn: callable + :return: the wrapped function + :rtype: callable + """ + + @functools.wraps(fn) + def wrapper(*args, **kwargs): + started_here = not tracemalloc.is_tracing() + if started_here: + tracemalloc.start() + tracemalloc.reset_peak() + mem_before = tracemalloc.get_traced_memory()[0] + start = time.perf_counter() + + try: + return fn(*args, **kwargs) + finally: + elapsed = time.perf_counter() - start + peak = tracemalloc.get_traced_memory()[1] + if started_here: + tracemalloc.stop() + performance.counter += 1 + performance.total_time += elapsed + performance.total_mem += max(peak - mem_before, 0) + + return wrapper + + +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0 + + +if __name__ == "__main__": + + @performance + def build_list(n: int) -> list[int]: + return [i * i for i in range(n)] + + build_list(100_000) + build_list(50_000) + print(performance.counter, performance.total_time, performance.total_mem)