Skip to content

Commit dd1de13

Browse files
authored
Implement custom power, equation, and counter functions
Added custom functions for power, equation, and counter.
1 parent 71f5b39 commit dd1de13

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Week04/functions_Helin_Harman.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
custom_power = lambda x=0, e=1: x**e
2+
3+
4+
# ------------------
5+
# custom_equation
6+
# ------------------
7+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
8+
return (x**a + y**b) / c
9+
10+
# -------------
11+
# fn_w_counter
12+
# -------------
13+
14+
from typing import Tuple, Dict
15+
16+
def fn_w_counter(_state={'total': 0, 'callers': {}}) -> Tuple[int, Dict[str,int]]:
17+
_state['total'] += 1
18+
caller = __name__
19+
_state['callers'][caller] = _state['callers'].get(caller, 0) + 1
20+
return _state['total'], _state['callers']
21+
22+
23+
# custom_power test
24+
print(custom_power(2,3))
25+
26+
# custom_equation test
27+
print(custom_equation(2,3))
28+
print(custom_equation(3,5,a=2,b=3,c=4))
29+
30+
# fn_w_counter test
31+
for i in range(10):
32+
fn_w_counter()
33+
print(fn_w_counter()) # (11, {'__main__': 11})

0 commit comments

Comments
 (0)