Skip to content

Commit 3dd51e1

Browse files
authored
Add custom power and equation functions with counter
Added custom power function and custom equation function with detailed docstring. Implemented a call counter function to track total calls and caller counts.
1 parent 5ae1705 commit 3dd51e1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Week04/functions_elif_yalvac.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
custom_power = lambda x=0, /, e=1: x ** e
2+
3+
4+
5+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
6+
"""
7+
Calculates a specific mathematical expression.
8+
9+
:param x: Positional-only, default 0
10+
:param y: Positional-only, default 0
11+
:param a: Positional or keyword, default 1
12+
:param b: Positional or keyword, default 1
13+
:param c: Keyword-only, default 1
14+
:return: Returns (x**a + y**b) / c as a float
15+
"""
16+
return (x ** a + y ** b) / c
17+
18+
19+
20+
21+
from collections import defaultdict
22+
import inspect
23+
_total_calls = 0
24+
_caller_counts = defaultdict(int)
25+
def fn_w_counter() -> tuple[int, dict[str, int]]:
26+
global _total_calls
27+
_total_calls += 1
28+
caller = inspect.currentframe().f_back.f_globals.get('__name__', '<unknown>')
29+
_caller_counts[caller] += 1
30+
return _total_calls, dict(_caller_counts)

0 commit comments

Comments
 (0)