Skip to content

Commit 1596d1a

Browse files
committed
Add Week04 functions assignment - Feyza
1 parent f083b29 commit 1596d1a

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎Week04/functions_feyza_ozdemir.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import inspect
2+
3+
custom_power = lambda x=0, /, e=1: x ** e
4+
5+
6+
def custom_equation(
7+
x: int = 0,
8+
y: int = 0,
9+
/,
10+
a: int = 1,
11+
b: int = 1,
12+
*,
13+
c: int = 1
14+
) -> float:
15+
"""
16+
This function calculates the result of a custom mathematical equation.
17+
18+
:param x: The first base value (positional-only), defaults to 0.
19+
:type x: int
20+
:param y: The second base value (positional-only), defaults to 0.
21+
:type y: int
22+
:param a: The first exponent (positional-or-keyword), defaults to 1.
23+
:type a: int
24+
:param b: The second exponent (positional-or-keyword), defaults to 1.
25+
:type b: int
26+
:param c: The divisor (keyword-only), defaults to 1.
27+
:type c: int
28+
:return: The result of (x**a + y**b) / c as a float.
29+
:rtype: float
30+
"""
31+
return float((x ** a + y ** b) / c)
32+
33+
34+
def fn_w_counter() -> tuple[int, dict[str, int]]:
35+
"""
36+
This function counts total function calls and tracks calls per caller module.
37+
38+
:return: A tuple containing the total call count and a dictionary of caller counts.
39+
:rtype: tuple[int, dict[str, int]]
40+
"""
41+
caller_frame = inspect.currentframe().f_back
42+
caller_name = caller_frame.f_globals.get("__name__", "__main__") if caller_frame else "__main__"
43+
44+
fn_w_counter.total_calls += 1
45+
fn_w_counter.caller_counts[caller_name] = fn_w_counter.caller_counts.get(caller_name, 0) + 1
46+
47+
return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts)
48+
49+
50+
fn_w_counter.total_calls = 0
51+
fn_w_counter.caller_counts = {}

0 commit comments

Comments
 (0)