diff --git a/Week03/pyramid_tarik_bozgan.py b/Week03/pyramid_tarik_bozgan.py new file mode 100644 index 00000000..fa762647 --- /dev/null +++ b/Week03/pyramid_tarik_bozgan.py @@ -0,0 +1,7 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + while(number_of_blocks >= 0): + height += 1 + number_of_blocks -= height + return height - 1 + diff --git a/Week03/sequences_tarik_bozgan.py b/Week03/sequences_tarik_bozgan.py new file mode 100644 index 00000000..1ba02067 --- /dev/null +++ b/Week03/sequences_tarik_bozgan.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] += 1 + else: + counts[item] = 1 + return counts + + +def reverse_dict(d): + reversed_dict = {} + for key, value in d.items(): + reversed_dict[value] = key + return reversed_dict \ No newline at end of file diff --git a/Week04/decorators_tarik_bozgan.py b/Week04/decorators_tarik_bozgan.py new file mode 100644 index 00000000..9200e400 --- /dev/null +++ b/Week04/decorators_tarik_bozgan.py @@ -0,0 +1,21 @@ +import time +import tracemalloc + +def performance(func): + func.counter = 0 + func.total_time = 0 + func.total_mem = 0 + + def wrapper(*args, **kwargs): + func.counter += 1 + start_time = time.perf_counter() + tracemalloc.start() + result = func(*args, **kwargs) + current, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + func.total_time += (time.perf_counter() - start_time) + func.total_mem += peak + + return result + + return wrapper diff --git a/Week04/functions_tarik_bozgan.py b/Week04/functions_tarik_bozgan.py new file mode 100644 index 00000000..f3645f6a --- /dev/null +++ b/Week04/functions_tarik_bozgan.py @@ -0,0 +1,21 @@ +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: + """ + Calculate a custom equation: (x**a + y**b) / c + + :param x: First base value (positional-only) + :param y: Second base value (positional-only) + :param a: Exponent for x (positional-or-keyword) + :param b: Exponent for y (positional-or-keyword) + :param c: Divisor (keyword-only) + :return: The result of (x**a + y**b) / c + :rtype: float + """ + return (x**a + y**b) / c + +def fn_w_counter(_calls={"__main__": 0}): + _calls["__main__"] += 1 + return _calls["__main__"], dict(_calls) + +