Skip to content

Commit fea20f7

Browse files
authored
Merge pull request #813 from onurkonukk/patch-6
Create functions_onur_konuk.py
2 parents 4966edc + 204cdfa commit fea20f7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Week04/functions_onur_konuk.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 the value of the equation (x**a + y**b) / c.
6+
7+
:param x: Positional-only base value for the first term; defaults to 0.
8+
:param y: Positional-only base value for the second term; defaults to 0.
9+
:param a: Exponent for x; defaults to 1.
10+
:param b: Exponent for y; defaults to 1.
11+
:param c: Keyword-only divisor for the equation; defaults to 1.
12+
:return: Result of the equation as a float.
13+
:rtype: float
14+
:raises ZeroDivisionError: if c is 0.
15+
"""
16+
if c == 0:
17+
raise ZeroDivisionError("Division by zero is not allowed.")
18+
return (x**a + y**b) / c
19+
20+
def fn_w_counter() -> (int, dict[str, int]):
21+
"""
22+
Counts the number of times it has been called and tracks the caller.
23+
24+
:return: Tuple containing total call count and a dictionary with caller info.
25+
:rtype: tuple
26+
"""
27+
if not hasattr(fn_w_counter, "call_count"):
28+
fn_w_counter.call_count = 0
29+
fn_w_counter.callers_dict = {}
30+
31+
fn_w_counter.call_count += 1
32+
caller = __name__
33+
34+
if caller in fn_w_counter.callers_dict:
35+
fn_w_counter.callers_dict[caller] += 1
36+
else:
37+
fn_w_counter.callers_dict[caller] = 1
38+
39+
return fn_w_counter.call_count, fn_w_counter.callers_dict

0 commit comments

Comments
 (0)