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..f92cb3fa --- /dev/null +++ b/Week04/decorators_tarik_bozgan.py @@ -0,0 +1,24 @@ +import time +import sys +import functools +def performance(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + start_time = time.perf_counter() + + result = func(*args, **kwargs) + + end_time = time.perf_counter() + mem_usage = sys.getsizeof(result) + + wrapper.counter += 1 + wrapper.total_time += (end_time - start_time) + wrapper.total_mem += mem_usage + + return result + + wrapper.counter = 0 + wrapper.total_time = 0 + wrapper.total_mem = 0 + + return wrapper \ 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..01e864c6 --- /dev/null +++ b/Week04/functions_tarik_bozgan.py @@ -0,0 +1,29 @@ +import sys + +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: + """ + Belirtilen formüle göre kayan noktalı bir sayı döndürür. + + :param x: Konumsal-tek parametre (Varsayılan 0). + :param y: Konumsal-tek parametre (Varsayılan 0). + :param a: Konumsal-veya-anahtar kelime parametresi (Varsayılan 1). + :param b: Konumsal-veya-anahtar kelime parametresi (Varsayılan 1). + :param c: Anahtar kelime-tek parametre (Varsayılan 1). + :returns: (x**a + y**b) / c formülünün sonucunu döndürür. + :rtype: float + """ + return (x**a + y**b) / c + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, 'count'): + fn_w_counter.count = 0 + fn_w_counter.callers = {} + + caller_name = sys._getframe(1).f_globals['__name__'] + + fn_w_counter.count += 1 + fn_w_counter.callers[caller_name] = fn_w_counter.callers.get(caller_name, 0) + 1 + + return fn_w_counter.count, fn_w_counter.callers \ No newline at end of file