Skip to content

Commit a8e0eea

Browse files
Implement custom power and equation functions
Added custom_power function and custom_equation for calculations.
1 parent 6b0ce98 commit a8e0eea

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎Week04/functions_bugra_ozturk.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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: 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: Result of (x**a + y**b) / c as a float
14+
"""
15+
for name, value in (("x", x), ("y", y), ("a", a), ("b", b), ("c", c)):
16+
if not isinstance(value, int):
17+
raise TypeError(f"{name} must be an integer")
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, "total"):
23+
fn_w_counter.total = 0
24+
fn_w_counter.callers = {}
25+
fn_w_counter.total += 1
26+
fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1
27+
return fn_w_counter.total, fn_w_counter.callers

0 commit comments

Comments
 (0)