Skip to content

Commit 94a10b2

Browse files
authored
Add custom power and equation functions
1 parent 71f5b39 commit 94a10b2

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Week04/functions_helin_harman.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import inspect
2+
3+
4+
# -------------------------------------------------
5+
# custom_power
6+
# -------------------------------------------------
7+
custom_power = lambda x=0, /, e=1: x**e
8+
9+
10+
# -------------------------------------------------
11+
# custom_equation
12+
# -------------------------------------------------
13+
def custom_equation(
14+
x: int = 0,
15+
y: int = 0,
16+
/,
17+
a: int = 1,
18+
b: int = 1,
19+
*,
20+
c: int = 1,
21+
) -> float:
22+
"""
23+
Calculate a custom equation.
24+
25+
:param x: positional-only integer
26+
:param y: positional-only integer
27+
:param a: positional-or-keyword integer
28+
:param b: positional-or-keyword integer
29+
:param c: keyword-only integer
30+
:return: result of the equation
31+
"""
32+
33+
for name, value in {"x": x, "y": y, "a": a, "b": b, "c": c}.items():
34+
if not isinstance(value, int):
35+
raise TypeError(f"{name} must be int")
36+
37+
return (x**a + y**b) / c
38+
39+
40+
# -------------------------------------------------
41+
# fn_w_counter
42+
# -------------------------------------------------
43+
_counter = 0
44+
_callers = {}
45+
46+
47+
def fn_w_counter() -> (int, dict[str, int]):
48+
global _counter # ✅ sadece bu global gerekli
49+
50+
_counter += 1
51+
52+
module_name = inspect.getmodule(fn_w_counter).__name__
53+
_callers[module_name] = _callers.get(module_name, 0) + 1
54+
55+
return _counter, {module_name: _callers[module_name]}

0 commit comments

Comments
 (0)