Skip to content

Commit 77b121a

Browse files
authored
Implement custom power and equation functions
Adds custom power and equation functions with input validation.
1 parent 71f5b39 commit 77b121a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Week04/functions_emine_cetin.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
custom_power = lambda x=0, /, e=1: x ** e
2+
3+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
4+
"""
5+
Calculates the equation (x**a + y**b) / c.
6+
7+
:param x: Base for the first term (positional only)
8+
:param y: Base for the second term (positional only)
9+
:param a: Exponent for the first term
10+
:param b: Exponent for the second term
11+
:param c: Divisor (keyword only)
12+
:return: The result as a float
13+
"""
14+
if not all(isinstance(arg, int) for arg in [x, y, a, b, c]):
15+
raise TypeError("All arguments must be integers.")
16+
17+
return float((x ** a + y ** b) / c)
18+
19+
_call_count = 0
20+
21+
def fn_w_counter() -> (int, dict[str, int]):
22+
global _call_count
23+
_call_count += 1
24+
25+
return _call_count, {__name__: _call_count}

0 commit comments

Comments
 (0)