Skip to content

Commit aa7b919

Browse files
authored
Merge pull request #1060 from Batuhaanccs/patch-5
Add custom mathematical functions and call counter
2 parents 097076a + 7e05fe8 commit aa7b919

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎Week04/functions_batuhan_tunc.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 result of the equation (x**a + y**b) / c.
7+
8+
:param x: The first base, positional-only
9+
:type x: int
10+
:param y: The second base, positional-only
11+
:type y: int
12+
:param a: The exponent of x, positional-or-keyword
13+
:type a: int
14+
:param b: The exponent of y, positional-or-keyword
15+
:type b: int
16+
:param c: The divisor, keyword-only
17+
:type c: int
18+
:raises TypeError: If any of the arguments is not an integer
19+
:return: The result of (x**a + y**b) / c
20+
:rtype: float
21+
"""
22+
for name, value in (("x", x), ("y", y), ("a", a), ("b", b), ("c", c)):
23+
if not isinstance(value, int):
24+
raise TypeError(f"{name} must be an integer")
25+
return (x ** a + y ** b) / c
26+
27+
28+
def fn_w_counter() -> (int, dict[str, int]):
29+
if not hasattr(fn_w_counter, "total_calls"):
30+
fn_w_counter.total_calls = 0
31+
fn_w_counter.callers = {}
32+
caller = __name__
33+
fn_w_counter.total_calls += 1
34+
fn_w_counter.callers[caller] = fn_w_counter.callers.get(caller, 0) + 1
35+
return fn_w_counter.total_calls, fn_w_counter.callers

0 commit comments

Comments
 (0)