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..8085d711 --- /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() -> (int, dict[str, int]): + calls[__name__] = calls.get(__name__, 0) + 1 + return sum(calls.values()), calls \ No newline at end of file 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