Skip to content

Commit 65def47

Browse files
Implement custom equation and function call counter
Added custom equation function and call counter.
1 parent 8415c79 commit 65def47

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎Week04/functions_sinem_tanriver.py‎

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

0 commit comments

Comments
 (0)