Skip to content

Commit 591a020

Browse files
Implement custom power and equation functions
Added custom_power and custom_equation functions, along with a function to count calls to fn_w_counter.
1 parent 8415c79 commit 591a020

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎Week04/functions_sinem_tanriver.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
Computes the value of (x**a + y**b) / c.
7+
8+
:param x: First base, positional-only
9+
:type x: int
10+
:param y: Second base, positional-only
11+
:type y: int
12+
:param a: Exponent of x
13+
:type a: int
14+
:param b: Exponent of y
15+
:type b: int
16+
:param c: Divisor, keyword-only
17+
:type c: int
18+
:return: Result of (x**a + y**b) / c
19+
:rtype: float
20+
"""
21+
return (x ** a + y ** b) / c
22+
23+
24+
def fn_w_counter() -> (int, dict[str, int]):
25+
caller = __name__
26+
fn_w_counter.total += 1
27+
fn_w_counter.callers[caller] = fn_w_counter.callers.get(caller, 0) + 1
28+
return fn_w_counter.total, fn_w_counter.callers
29+
30+
31+
fn_w_counter.total = 0
32+
fn_w_counter.callers = {}

0 commit comments

Comments
 (0)