Skip to content

Commit 7724b61

Browse files
authored
functions_miray_cengil.py
1 parent a59ad33 commit 7724b61

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Week04/functions_miray_cengil.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
def custom_power(x=0, /, e=1):
2-
"""A lambda function that calculates x raised to the power of e."""
3-
return (lambda x, e: x ** e)(x, e) #Direct Calculation
1+
custom_power = lambda x=0, e=1: x ** e
42

53
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
64

@@ -19,18 +17,19 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int
1917
return (x**a + y**b) / c
2018

2119
from collections import defaultdict
20+
import inspect
2221

2322
call_count = defaultdict(int)
2423

25-
def fn_w_counter()-> tuple[int, dict[str, int]]:
24+
def fn_w_counter()-> (int, dict[str, int]):
2625
"""A function that counts the number of calls."""
27-
call_count = defaultdict(int)
28-
29-
def wrapper() -> tuple[int, dict[str, int]]:
30-
import inspect
31-
caller_name = inspect.stack()[1].function
32-
call_count[caller_name] += 1
33-
total_calls = sum(call_count.values())
34-
return total_calls, dict(call_count)
35-
36-
return wrapper
26+
caller_name = inspect.stack()[1].function # Get the name of the calling function
27+
28+
# Increment the global counter
29+
call_count[caller_name] += 1
30+
31+
# Calculate the total number of calls
32+
total_calls = sum(call_count.values())
33+
34+
# Return the total call count and the call counts for each function
35+
return total_calls, dict(call_count)

0 commit comments

Comments
 (0)