Skip to content

Commit a1b73b3

Browse files
authored
Add custom power and equation functions with counter
1 parent 71f5b39 commit a1b73b3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Week04/functions_utku_yuksel.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import inspect
2+
3+
custom_power = lambda x=0, /, e=1: x**e
4+
5+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
6+
"""
7+
Computes the result of the equation (x**a + y**b) / c.
8+
9+
:param x: The first base integer
10+
:type x: int
11+
:param y: The second base integer
12+
:type y: int
13+
:param a: The first exponent
14+
:type a: int
15+
:param b: The second exponent
16+
:type b: int
17+
:param c: The divisor
18+
:type c: int
19+
:return: The result of the equation as a float
20+
:rtype: float
21+
"""
22+
return (x**a + y**b) / c
23+
24+
def fn_w_counter() -> tuple[int, dict]:
25+
if not hasattr(fn_w_counter, 'total_calls'):
26+
fn_w_counter.total_calls = 0
27+
fn_w_counter.caller_counts = {}
28+
29+
fn_w_counter.total_calls += 1
30+
31+
try:
32+
frame = inspect.currentframe().f_back
33+
caller_name = frame.f_globals['__name__']
34+
except (AttributeError, KeyError):
35+
caller_name = 'unknown'
36+
37+
if caller_name in fn_w_counter.caller_counts:
38+
fn_w_counter.caller_counts[caller_name] += 1
39+
else:
40+
fn_w_counter.caller_counts[caller_name] = 1
41+
42+
return fn_w_counter.total_calls, fn_w_counter.caller_counts

0 commit comments

Comments
 (0)