Skip to content

Commit 75f708f

Browse files
committed
Week04 homeworks done
1 parent 53ed69c commit 75f708f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Week04/decorators_tarik_bozgan.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import time
2+
import tracemalloc
3+
4+
def performance(func):
5+
func.counter = 0
6+
func.total_time = 0
7+
func.total_mem = 0
8+
9+
def wrapper(*args, **kwargs):
10+
func.counter += 1
11+
start_time = time.perf_counter()
12+
tracemalloc.start()
13+
result = func(*args, **kwargs)
14+
current, peak = tracemalloc.get_traced_memory()
15+
tracemalloc.stop()
16+
func.total_time += (time.perf_counter() - start_time)
17+
func.total_mem += peak
18+
19+
return result
20+
21+
return wrapper

Week04/functions_tarik_bozgan.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
custom_power = lambda x=0, /, e=1: x**e
2+
3+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
4+
"""
5+
Calculate a custom equation: (x**a + y**b) / c
6+
7+
:param x: First base value (positional-only)
8+
:param y: Second base value (positional-only)
9+
:param a: Exponent for x (positional-or-keyword)
10+
:param b: Exponent for y (positional-or-keyword)
11+
:param c: Divisor (keyword-only)
12+
:return: The result of (x**a + y**b) / c
13+
:rtype: float
14+
"""
15+
return (x**a + y**b) / c
16+
17+
def fn_w_counter(_calls={"__main__": 0}):
18+
_calls["__main__"] += 1
19+
return _calls["__main__"], dict(_calls)
20+
21+

0 commit comments

Comments
 (0)