Skip to content

Commit ec761d3

Browse files
authored
Add custom power and equation functions
1 parent b60efee commit ec761d3

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎Week04/functions_jalil_guliyev.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
custom_power = lambda x=0, /, e=1: x ** e
3+
4+
5+
def custom_equation(
6+
x: int = 0, y: int = 0, /,
7+
a: int = 1, b: int = 1, *, c: int = 1
8+
) -> float:
9+
"""Calculate the result of an equation.
10+
11+
:param x: First base.
12+
:param y: Second base.
13+
:param a: Exponent of x.
14+
:param b: Exponent of y.
15+
:param c: Divisor.
16+
:return: The result of (x**a + y**b) / c.
17+
"""
18+
if any(type(value) is not int for value in (x, y, a, b, c)):
19+
raise TypeError("All parameters must be integers")
20+
21+
return (x ** a + y ** b) / c
22+
23+
24+
def fn_w_counter() -> (int, dict[str, int]):
25+
if not hasattr(fn_w_counter, "counter"):
26+
fn_w_counter.counter = 0
27+
fn_w_counter.callers = {}
28+
29+
fn_w_counter.counter += 1
30+
caller = __name__
31+
fn_w_counter.callers[caller] = (
32+
fn_w_counter.callers.get(caller, 0) + 1
33+
)
34+
35+
return fn_w_counter.counter, fn_w_counter.callers.copy()
36+

0 commit comments

Comments
 (0)