Skip to content

Commit 76e73bd

Browse files
committed
Week04 homeworks are done.
1 parent 75f708f commit 76e73bd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Week04/functions_tarik_bozgan.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,19 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int
1414
"""
1515
return (x**a + y**b) / c
1616

17-
def fn_w_counter(_calls={"__main__": 0}):
18-
_calls["__main__"] += 1
19-
return _calls["__main__"], dict(_calls)
17+
def fn_w_counter() -> tuple[int, dict[str, int]]:
18+
19+
caller = __name__
20+
21+
if not hasattr(fn_w_counter, "total"):
22+
fn_w_counter.total = 0
23+
if not hasattr(fn_w_counter, "callers"):
24+
fn_w_counter.callers = {}
25+
26+
fn_w_counter.total += 1
27+
fn_w_counter.callers[caller] = fn_w_counter.callers.get(caller, 0) + 1
28+
29+
return fn_w_counter.total, fn_w_counter.callers.copy()
30+
2031

2132

0 commit comments

Comments
 (0)