From f2d591d632768cd277f093d9c5b9ca3f87c81c7b Mon Sep 17 00:00:00 2001 From: Eren Ozturk Date: Mon, 16 Nov 2026 19:26:22 +0300 Subject: [PATCH 1/3] Add Week03 and Week04 homeworks - Eren Ozturk --- Week03/pyramid_eren_ozturk.py | 9 +++++++++ Week03/sequences_eren_ozturk.py | 23 +++++++++++++++++++++++ Week04/decorators_eren_ozturk.py | 28 ++++++++++++++++++++++++++++ Week04/functions_eren_ozturk.py | 22 ++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 Week03/pyramid_eren_ozturk.py create mode 100644 Week03/sequences_eren_ozturk.py create mode 100644 Week04/decorators_eren_ozturk.py create mode 100644 Week04/functions_eren_ozturk.py diff --git a/Week03/pyramid_eren_ozturk.py b/Week03/pyramid_eren_ozturk.py new file mode 100644 index 00000000..36ae6f11 --- /dev/null +++ b/Week03/pyramid_eren_ozturk.py @@ -0,0 +1,9 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + layer_blocks = 1 + + while number_of_blocks >= layer_blocks: + number_of_blocks = number_of_blocks - layer_blocks + height = height + 1 + layer_blocks = layer_blocks + 1 + return height \ No newline at end of file diff --git a/Week03/sequences_eren_ozturk.py b/Week03/sequences_eren_ozturk.py new file mode 100644 index 00000000..b75001d6 --- /dev/null +++ b/Week03/sequences_eren_ozturk.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] = counts[item] + 1 + else: + counts[item] = 1 + return counts + + +def reverse_dict(d): + reversed_d = {} + for key, value in d.items(): + reversed_d[value] = key + return reversed_d \ No newline at end of file diff --git a/Week04/decorators_eren_ozturk.py b/Week04/decorators_eren_ozturk.py new file mode 100644 index 00000000..0d7c20c9 --- /dev/null +++ b/Week04/decorators_eren_ozturk.py @@ -0,0 +1,28 @@ +import time +import tracemalloc + + +def performance(func): + def wrapper(*args, **kwargs): + performance.counter = performance.counter + 1 + + tracemalloc.start() + start_time = time.perf_counter() + + result = func(*args, **kwargs) + + end_time = time.perf_counter() + current_mem, peak_mem = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.total_time = performance.total_time + (end_time - start_time) + performance.total_mem = performance.total_mem + peak_mem + + 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_eren_ozturk.py b/Week04/functions_eren_ozturk.py new file mode 100644 index 00000000..cc1e323b --- /dev/null +++ b/Week04/functions_eren_ozturk.py @@ -0,0 +1,22 @@ +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: + """Computes (x**a + y**b) / c. + + :param x: First base + :param y: Second base + :param a: Exponent of x + :param b: Exponent of y + :param c: Divisor + :return: (x**a + y**b) / c + """ + return (x ** a + y ** b) / c + + +calls = {} + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + calls[__name__] = calls.get(__name__, 0) + 1 + return sum(calls.values()), calls \ No newline at end of file From 95c4236cf8efda334107d809d68d6d2d3692675a Mon Sep 17 00:00:00 2001 From: Eren Ozturk Date: Mon, 16 Nov 2026 19:32:33 +0300 Subject: [PATCH 2/3] Fix return annotation in Week04 functions. --- Week04/functions_eren_ozturk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_eren_ozturk.py b/Week04/functions_eren_ozturk.py index cc1e323b..8085d711 100644 --- a/Week04/functions_eren_ozturk.py +++ b/Week04/functions_eren_ozturk.py @@ -17,6 +17,6 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int calls = {} -def fn_w_counter() -> tuple[int, dict[str, int]]: +def fn_w_counter() -> (int, dict[str, int]): calls[__name__] = calls.get(__name__, 0) + 1 return sum(calls.values()), calls \ No newline at end of file From a0efd5d50ea75650947a8414e564401fecc6d821 Mon Sep 17 00:00:00 2001 From: Eren Ozturk Date: Thu, 19 Nov 2026 00:32:18 +0300 Subject: [PATCH 3/3] Add Week05 homework - Eren Ozturk --- Week05/emails_eren_ozturk.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Week05/emails_eren_ozturk.py diff --git a/Week05/emails_eren_ozturk.py b/Week05/emails_eren_ozturk.py new file mode 100644 index 00000000..bb3269a5 --- /dev/null +++ b/Week05/emails_eren_ozturk.py @@ -0,0 +1,30 @@ +class Emails(list): + def __init__(self, emails=None): + if emails is None: + emails = [] + self.validate(emails) + unique_emails = [] + for email in emails: + if email not in unique_emails: + unique_emails.append(email) + self.data = unique_emails + super().__init__(unique_emails) + + def validate(self, emails): + for email in emails: + if not isinstance(email, str): + raise ValueError("All elements must be strings.") + if "@" not in email: + raise ValueError("Invalid email address.") + parts = email.split("@") + if len(parts) != 2 or not parts[0] or "." not in parts[1]: + raise ValueError("Invalid email address.") + domain_parts = parts[1].split(".") + if not domain_parts[0] or not domain_parts[-1]: + raise ValueError("Invalid email address.") + + def __repr__(self): + return f"Emails({self.data})" + + def __str__(self): + return f"Emails: {self.data}" \ No newline at end of file