diff --git a/Week01/info_bugra_ozturk.py b/Week01/info_bugra_ozturk.py new file mode 100644 index 00000000..381cbac0 --- /dev/null +++ b/Week01/info_bugra_ozturk.py @@ -0,0 +1,2 @@ +student_id = "230316041" +full_name = "Buğra Öztürk" diff --git a/Week02/types_bugra_ozturk.py b/Week02/types_bugra_ozturk.py new file mode 100644 index 00000000..3fa0f5e3 --- /dev/null +++ b/Week02/types_bugra_ozturk.py @@ -0,0 +1,4 @@ +my_int = 25 +my_float = 3.14 +my_bool = True +my_complex = 2 + 3j diff --git a/Week03/pyramid_bugra_ozturk.py b/Week03/pyramid_bugra_ozturk.py new file mode 100644 index 00000000..98ce056b --- /dev/null +++ b/Week03/pyramid_bugra_ozturk.py @@ -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 diff --git a/Week03/sequences_bugra_ozturk.py b/Week03/sequences_bugra_ozturk.py new file mode 100644 index 00000000..b9074067 --- /dev/null +++ b/Week03/sequences_bugra_ozturk.py @@ -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()} diff --git a/Week04/decorators_bugra_ozturk.py b/Week04/decorators_bugra_ozturk.py new file mode 100644 index 00000000..aca3d203 --- /dev/null +++ b/Week04/decorators_bugra_ozturk.py @@ -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 diff --git a/Week04/functions_bugra_ozturk.py b/Week04/functions_bugra_ozturk.py new file mode 100644 index 00000000..ef57818c --- /dev/null +++ b/Week04/functions_bugra_ozturk.py @@ -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