Skip to content
Open
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

26 changes: 26 additions & 0 deletions Week04/decorators_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions Week04/functions_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -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}