From c4e1b20823c27dbc0d4e33ee8971c0044af7ecdf Mon Sep 17 00:00:00 2001 From: YigithanErken16 Date: Sat, 31 Oct 2026 17:05:45 +0300 Subject: [PATCH 1/5] Week 02 homework added --- Week02/types_yigithan_erken.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Week02/types_yigithan_erken.py diff --git a/Week02/types_yigithan_erken.py b/Week02/types_yigithan_erken.py new file mode 100644 index 00000000..f64e8096 --- /dev/null +++ b/Week02/types_yigithan_erken.py @@ -0,0 +1,4 @@ +my_int = 1903 +my_float = 19.03 +my_bool = True +my_complex = 190 + 3j \ No newline at end of file From 56cd50278a58be6919d1d372b6ae2f5b7728ddf5 Mon Sep 17 00:00:00 2001 From: YigithanErken16 Date: Sat, 31 Oct 2026 17:22:31 +0300 Subject: [PATCH 2/5] Week03 homeworks added --- Week03/pyramid_yigithan_erken.py | 8 ++++++++ Week03/sequences_yigithan_erken.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Week03/pyramid_yigithan_erken.py create mode 100644 Week03/sequences_yigithan_erken.py diff --git a/Week03/pyramid_yigithan_erken.py b/Week03/pyramid_yigithan_erken.py new file mode 100644 index 00000000..dae611cd --- /dev/null +++ b/Week03/pyramid_yigithan_erken.py @@ -0,0 +1,8 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + used = 1 + while number_of_blocks >= used: + number_of_blocks -= used + height += 1 + used += 1 + return height diff --git a/Week03/sequences_yigithan_erken.py b/Week03/sequences_yigithan_erken.py new file mode 100644 index 00000000..6b9827b5 --- /dev/null +++ b/Week03/sequences_yigithan_erken.py @@ -0,0 +1,17 @@ +def remove_duplicates(seq: list) -> list: + return list(set(seq)) + +def list_counts(seq: list) -> dict: + counts = {} + for item in seq: + if item in counts: + counts[item] += 1 + else: + counts[item] = 1 + return counts + +def reverse_dict(d: dict) -> dict: + reversed_dict = {} + for key, value in d.items(): + reversed_dict[value] = key + return reversed_dict \ No newline at end of file From aef97dfa3d591aed982e1674ecc53688e631a46d Mon Sep 17 00:00:00 2001 From: YigithanErken16 Date: Sat, 31 Oct 2026 17:36:06 +0300 Subject: [PATCH 3/5] Week04 homeworks added --- Week04/decorators_yigithan_erken.py | 28 ++++++++++++++++++++++++ Week04/functions_yigithan_erken.py | 33 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Week04/decorators_yigithan_erken.py create mode 100644 Week04/functions_yigithan_erken.py diff --git a/Week04/decorators_yigithan_erken.py b/Week04/decorators_yigithan_erken.py new file mode 100644 index 00000000..ab423c18 --- /dev/null +++ b/Week04/decorators_yigithan_erken.py @@ -0,0 +1,28 @@ +import time +import tracemalloc +from functools import wraps + +def performance(func): + @wraps(func) + def wrapper(*args, **kwargs): + performance.counter += 1 + + tracemalloc.start() + start_time = time.perf_counter() + + result = func(*args, **kwargs) + + end_time = time.perf_counter() + current, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.total_time += (end_time - start_time) + performance.total_mem += peak + + return result + + return wrapper + +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0 \ No newline at end of file diff --git a/Week04/functions_yigithan_erken.py b/Week04/functions_yigithan_erken.py new file mode 100644 index 00000000..33df1315 --- /dev/null +++ b/Week04/functions_yigithan_erken.py @@ -0,0 +1,33 @@ +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 a custom equation. + + :param x: Positional-only integer, defaults to 0. + :param y: Positional-only integer, defaults to 0. + :param a: Positional-or-keyword integer, defaults to 1. + :param b: Positional-or-keyword integer, defaults to 1. + :param c: Keyword-only integer, defaults to 1. + :return: The result of (x**a + y**b) / c as float. + """ + if not all(isinstance(val, int) for val in (x, y, a, b, c)): + raise TypeError("Arguments must be integers.") + + return float((x**a + y**b) / c) + +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 = {} + + caller_name = __name__ + + fn_w_counter.total_calls += 1 + + if caller_name in fn_w_counter.caller_counts: + fn_w_counter.caller_counts[caller_name] += 1 + else: + fn_w_counter.caller_counts[caller_name] = 1 + + return (fn_w_counter.total_calls, fn_w_counter.caller_counts) \ No newline at end of file From 81c5be537502ace77132426b35ff095ae9e11306 Mon Sep 17 00:00:00 2001 From: YigithanErken16 Date: Sat, 31 Oct 2026 17:43:42 +0300 Subject: [PATCH 4/5] Week05 homework added --- Week05/emails_yigithan_erken.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Week05/emails_yigithan_erken.py diff --git a/Week05/emails_yigithan_erken.py b/Week05/emails_yigithan_erken.py new file mode 100644 index 00000000..e67f2d73 --- /dev/null +++ b/Week05/emails_yigithan_erken.py @@ -0,0 +1,27 @@ +class Emails(list): + def __init__(self, initial_emails=None): + super().__init__() + self.data = self + if initial_emails is not None: + self.validate(initial_emails) + + def validate(self, emails_to_check): + for item in emails_to_check: + if not isinstance(item, str): + raise ValueError("List can only contain strings") + + if "@" not in item: + raise ValueError("Invalid email format") + + domain_part = item.split("@")[1] + if "." not in domain_part: + raise ValueError("Invalid email format") + + if item not in self: + self.append(item) + + def __repr__(self): + return f"Emails({super().__repr__()})" + + def __str__(self): + return super().__str__() \ No newline at end of file From 1a0d670f814747cbdc3e29db6828c627e7e676fc Mon Sep 17 00:00:00 2001 From: YigithanErken16 Date: Tue, 3 Nov 2026 13:23:55 +0300 Subject: [PATCH 5/5] Solved the decorators homework without using functools module. --- Week04/decorators_yigithan_erken.py | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Week04/decorators_yigithan_erken.py b/Week04/decorators_yigithan_erken.py index ab423c18..67ba7979 100644 --- a/Week04/decorators_yigithan_erken.py +++ b/Week04/decorators_yigithan_erken.py @@ -1,28 +1,31 @@ import time import tracemalloc -from functools import wraps def performance(func): - @wraps(func) + def wrapper(*args, **kwargs): - performance.counter += 1 tracemalloc.start() - start_time = time.perf_counter() - - result = func(*args, **kwargs) - - end_time = time.perf_counter() - current, peak = tracemalloc.get_traced_memory() - tracemalloc.stop() - - performance.total_time += (end_time - start_time) - performance.total_mem += peak + start = time.perf_counter() + start_mem = tracemalloc.get_traced_memory()[0] + tracemalloc.reset_peak() + + try: + result = func(*args, **kwargs) + finally: + end = time.perf_counter() + current, peak = tracemalloc.get_traced_memory() + + performance.counter += 1 + performance.total_time += end - start + performance.total_mem += peak - start_mem + + tracemalloc.stop() + return result - return wrapper performance.counter = 0 -performance.total_time = 0.0 +performance.total_time = 0 performance.total_mem = 0 \ No newline at end of file