Skip to content
Closed
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
7 changes: 7 additions & 0 deletions Week03/pyramid_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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

23 changes: 23 additions & 0 deletions Week04/decorators_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions Week04/functions_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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__ != "<lambda>" 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()
Loading