Skip to content

Commit 5f0026b

Browse files
authored
Implement custom power and equation functions
Added custom_power lambda and custom_equation function for mathematical operations, along with a call counter function.
1 parent 2024d08 commit 5f0026b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

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+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
5+
"""
6+
This function calculates (x**a + y**b) / c.
7+
8+
:param x: First base, positional-only
9+
:param y: Second base, positional-only
10+
:param a: Exponent of x
11+
:param b: Exponent of y
12+
:param c: Divisor, keyword-only
13+
:return: The result of (x**a + y**b) / c
14+
"""
15+
for value in (x, y, a, b, c):
16+
if type(value) is not int:
17+
raise TypeError("All parameters must be integers.")
18+
return (x ** a + y ** b) / c
19+
20+
21+
def fn_w_counter() -> (int, dict[str, int]):
22+
if not hasattr(fn_w_counter, "call_counter"):
23+
fn_w_counter.call_counter = 0
24+
fn_w_counter.callers = {}
25+
fn_w_counter.call_counter += 1
26+
if __name__ in fn_w_counter.callers:
27+
fn_w_counter.callers[__name__] += 1
28+
else:
29+
fn_w_counter.callers[__name__] = 1
30+
return fn_w_counter.call_counter, fn_w_counter.callers

0 commit comments

Comments
 (0)