Skip to content

Commit a7ad573

Browse files
authored
Add custom power and equation functions with counter
1 parent 71f5b39 commit a7ad573

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Week04/function_almira_keles.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from __future__ import annotations
2+
3+
import inspect
4+
from typing import Any, Dict, Tuple
5+
6+
7+
custom_power = lambda x=0, /, e=1: x**e
8+
9+
10+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
11+
12+
return (x**a + y**b) / c
13+
14+
15+
def fn_w_counter() -> Tuple[int, Dict[str, int]]:
16+
17+
18+
if not hasattr(fn_w_counter, "_total"):
19+
fn_w_counter._total = 0 # type: ignore[attr-defined]
20+
if not hasattr(fn_w_counter, "_by_caller"):
21+
fn_w_counter._by_caller = {} # type: ignore[attr-defined]
22+
23+
24+
frame = inspect.currentframe()
25+
caller_frame = frame.f_back if frame is not None else None
26+
caller_name = "<unknown>"
27+
if caller_frame is not None:
28+
caller_name = str(caller_frame.f_globals.get("__name__", "<unknown>"))
29+
30+
31+
fn_w_counter._total += 1 # type: ignore[attr-defined]
32+
by_caller: Dict[str, int] = fn_w_counter._by_caller # type: ignore[attr-defined]
33+
by_caller[caller_name] = by_caller.get(caller_name, 0) + 1
34+
35+
36+
return int(fn_w_counter._total), dict(by_caller) # type: ignore[attr-defined]
37+
Footer
38+
© 2026 Git

0 commit comments

Comments
 (0)