Skip to content

Commit 6c64a1d

Browse files
authored
Add custom power and equation functions
Implement custom power and equation functions with type checks and a call counter.
1 parent 71f5b39 commit 6c64a1d

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import inspect
2+
3+
4+
custom_power = lambda x=0, /, e=1: x ** e
5+
6+
7+
def custom_equation(
8+
x: int = 0,
9+
y: int = 0,
10+
/,
11+
a: int = 1,
12+
b: int = 1,
13+
*,
14+
c: int = 1
15+
) -> float:
16+
"""
17+
:param x: first integer value
18+
:param y: second integer value
19+
:param a: coefficient for x
20+
:param b: coefficient for y
21+
:param c: divisor
22+
:return: result of the equation
23+
"""
24+
25+
for name, value in {"x": x, "y": y, "a": a, "b": b, "c": c}.items():
26+
if not isinstance(value, int):
27+
raise TypeError(f"{name} must be int")
28+
29+
return (x * a + y * b) / c
30+
31+
32+
_fn_total_counter = 0
33+
_fn_callers: dict[str, int] = {}
34+
35+
36+
def fn_w_counter() -> (int, dict[str, int]):
37+
global _fn_total_counter, _fn_callers
38+
39+
_fn_total_counter += 1
40+
41+
caller_module = inspect.stack()[1].frame.f_globals.get("__name__", "__main__")
42+
43+
_fn_callers[caller_module] = _fn_callers.get(caller_module, 0) + 1
44+
45+
return _fn_total_counter, {caller_module: _fn_callers[caller_module]}

0 commit comments

Comments
 (0)