Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Week03/pyramid_eren_ozturk.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions Week03/sequences_eren_ozturk.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions Week04/decorators_eren_ozturk.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions Week04/functions_eren_ozturk.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions Week05/emails_eren_ozturk.py
Original file line number Diff line number Diff line change
@@ -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}"
Loading