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/Week04/decorators_tarik_bozgan.py b/Week04/decorators_tarik_bozgan.py new file mode 100644 index 00000000..3d4dd207 --- /dev/null +++ b/Week04/decorators_tarik_bozgan.py @@ -0,0 +1,23 @@ +import time, tracemalloc +from functools import wraps + +def performance(func): + performance.c = performance.c + 1 if hasattr(performance, "c") else 1 + performance.t = getattr(performance, "t", 0.0) + performance.m = getattr(performance, "m", 0) + + @wraps(func) + def wrapper(*a, **k): + performance.c += 1 + t0 = time.perf_counter() + tracemalloc.start() + r = func(*a, **k) + performance.t += time.perf_counter() - t0 + performance.m += tracemalloc.get_traced_memory()[1] + tracemalloc.stop() + return r + 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_tarik_bozgan.py b/Week04/functions_tarik_bozgan.py new file mode 100644 index 00000000..16fba91b --- /dev/null +++ b/Week04/functions_tarik_bozgan.py @@ -0,0 +1,23 @@ +custom_power = lambda x=0, /, e=1: x**e +"""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. + :param x: Base number 1 + :param y: Base number 2 + :param a: Exponent for x + :param b: Exponent for y + :param c: Divisor + :return: The calculated result as a float + """ + return (x**a + y**b) / c + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + caller = __name__ if __name__ != "" else "lambda" + fn_w_counter.total = getattr(fn_w_counter, "total", 0) + 1 + fn_w_counter.callers = getattr(fn_w_counter, "callers", {}) + fn_w_counter.callers[caller] = fn_w_counter.callers.get(caller, 0) + 1 + return fn_w_counter.total, fn_w_counter.callers.copy() \ No newline at end of file