Skip to content
2 changes: 2 additions & 0 deletions Week01/info_bugra_ozturk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
student_id = "230316041"
full_name = "Buğra Öztürk"
4 changes: 4 additions & 0 deletions Week02/types_bugra_ozturk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 25
my_float = 3.14
my_bool = True
my_complex = 2 + 3j
7 changes: 7 additions & 0 deletions Week03/pyramid_bugra_ozturk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def calculate_pyramid_height(number_of_blocks):
height = 0
used_blocks = 0
while used_blocks + (height + 1) <= number_of_blocks:
height += 1
used_blocks += height
return height
28 changes: 28 additions & 0 deletions Week03/sequences_bugra_ozturk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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()}
23 changes: 23 additions & 0 deletions Week04/decorators_bugra_ozturk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import time
import tracemalloc


def performance(func):
def _performance(*args, **kwargs):
tracemalloc.start()
start = time.perf_counter()
result = func(*args, **kwargs)
end = time.perf_counter()
_, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()

performance.counter += 1
performance.total_time += end - start
performance.total_mem += peak
return result
return _performance


performance.counter = 0
performance.total_time = 0
performance.total_mem = 0
27 changes: 27 additions & 0 deletions Week04/functions_bugra_ozturk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 the result of the equation (x**a + y**b) / c.

:param x: First base, positional-only
:param y: Second base, positional-only
:param a: Exponent of x
:param b: Exponent of y
:param c: Divisor, keyword-only
:return: Result of (x**a + y**b) / c as a float
"""
for name, value in (("x", x), ("y", y), ("a", a), ("b", b), ("c", c)):
if not isinstance(value, int):
raise TypeError(f"{name} must be an integer")
return (x ** a + y ** b) / c


def fn_w_counter() -> (int, dict[str, int]):
if not hasattr(fn_w_counter, "total"):
fn_w_counter.total = 0
fn_w_counter.callers = {}
fn_w_counter.total += 1
fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1
return fn_w_counter.total, fn_w_counter.callers