Skip to content

Commit 8b81d80

Browse files
authored
Merge pull request #749 from ugur-kurt/patch-4
Add custom power and equation functions with call counter
2 parents 491b940 + 765f69f commit 8b81d80

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎Week04/functions_ugur_kurt.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
custom_power = lambda x=0, /, e=1: x**e
2+
3+
4+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
5+
"""
6+
Calculates the equation (x**a + y**b) / c.
7+
8+
:param x: The base of the first term, positional-only
9+
:type x: int
10+
:param y: The base of the second term, positional-only
11+
:type y: int
12+
:param a: The exponent of the first term
13+
:type a: int
14+
:param b: The exponent of the second term
15+
:type b: int
16+
:param c: The divisor, keyword-only
17+
:type c: int
18+
:return: The result of (x**a + y**b) / c
19+
20+
"""
21+
22+
return (x**a + y**b) / c
23+
24+
25+
_total_calls = 0
26+
_calls_by_caller = {}
27+
28+
29+
def fn_w_counter() -> (int, dict[str, int]):
30+
31+
global _total_calls
32+
_total_calls += 1
33+
_calls_by_caller[__name__] = _calls_by_caller.get(__name__, 0) + 1
34+
return _total_calls, dict(_calls_by_caller)

0 commit comments

Comments
 (0)