Skip to content

Commit cbc4608

Browse files
committed
Add fn_w_counter for Week04
1 parent 709fd91 commit cbc4608

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

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+
def custom_equation(x: int=0, y: int=0, / ,a: int=1, b: int=1, *,c: int=1) ->float:
4+
"""
5+
This function makes arithmetic equations.
6+
7+
:param x:first number to be exponentiated
8+
:param y:second number to be exponentiated
9+
:param a:power of the first number
10+
:param b:power of the second number
11+
:param c:divior of the sum of exponentiated
12+
:return:returns the result of the equation
13+
"""
14+
return (x**a + y**b) / c
15+
16+
def fn_w_counter() -> tuple[int, dict[str, int]]:
17+
"""
18+
Counts the number of calls with caller information.
19+
20+
:return: A tuple of the total number of calls and a dictionary
21+
with callers as keys and their call counts as values.
22+
"""
23+
caller_name = __name__
24+
25+
if not hasattr(fn_w_counter, "calls"):
26+
fn_w_counter.calls = 0
27+
fn_w_counter.callers = {}
28+
29+
fn_w_counter.calls += 1
30+
fn_w_counter.callers[caller_name] = fn_w_counter.callers.get(caller_name, 0) + 1
31+
32+
return fn_w_counter.calls, fn_w_counter.callers

0 commit comments

Comments
 (0)