Skip to content

Commit 1aa9b02

Browse files
authored
Add Week 4 HW
Added custom_power lambda and custom_equation function for calculations. Implemented fn_w_counter to track function calls.
1 parent 9a399e7 commit 1aa9b02

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎Week04/functions_sedat_celik.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 and returns the custom equation
6+
7+
:param x: first positional-only base value, default is 0
8+
:type x: int
9+
:param y: second positional-only value, default is 0
10+
:type y: int
11+
:param a: exponent of x, default is 1
12+
:type a: int
13+
:param b: exponent of y, default is 1
14+
:type b: int
15+
:param c: keyword-only divisor value, default is 1
16+
:type c: int
17+
:return: the calculated result of the equation (x**a + y**b) / c
18+
:rtype: float
19+
"""
20+
21+
return float((x**a + y**b) / c)
22+
23+
24+
def fn_w_counter() -> tuple[int, dict[str, int]]:
25+
if not hasattr(fn_w_counter, "total_calls"):
26+
fn_w_counter.total_calls = 0
27+
fn_w_counter.caller_counts = {}
28+
29+
caller = __name__
30+
31+
fn_w_counter.total_calls += 1
32+
fn_w_counter.caller_counts[caller] = (
33+
fn_w_counter.caller_counts.get(caller, 0) + 1
34+
)
35+
36+
return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts)

0 commit comments

Comments
 (0)