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..7dd4d60a --- /dev/null +++ b/Week04/decorators_tarik_bozgan.py @@ -0,0 +1,26 @@ +import time +import tracemalloc + +def performance(func): + def wrapper(*args, **kwargs): + tracemalloc.start() + t1 = time.perf_counter() + + result = func(*args, **kwargs) + + t2 = time.perf_counter() + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + # Hata buradaydı: Sayaçları wrapper'a değil, performance fonksiyonuna ekliyoruz + performance.counter += 1 + performance.total_time += (t2 - t1) + performance.total_mem += peak + + return result + return wrapper + +# Testin beklediği özellikler (Attributes) ana fonksiyona atanmalı +performance.counter = 0 +performance.total_time = 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..165bdf25 --- /dev/null +++ b/Week04/functions_tarik_bozgan.py @@ -0,0 +1,25 @@ +# x parametresine =0 ekledik, testin istediği bu. +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: + """ + :param x: + :param y: + :param a: + :param b: + :param c: + :return: + """ + if not isinstance(x, int): raise TypeError("x must be int") + if not isinstance(y, int): raise TypeError("y must be int") + if not isinstance(a, int): raise TypeError("a must be int") + if not isinstance(b, int): raise TypeError("b must be int") + if not isinstance(c, int): raise TypeError("c must be int") + + return float((x ** a + y ** b) / c) + +_count = 0 +def fn_w_counter() -> (int, dict[str, int]): + global _count + _count += 1 + return _count, {__name__: _count} \ No newline at end of file