Skip to content

Commit 7c4f3a9

Browse files
authored
Update functions_aysegul_ezber.py
1 parent 40166c2 commit 7c4f3a9

File tree

1 file changed

+25
-56
lines changed

1 file changed

+25
-56
lines changed

Week04/functions_aysegul_ezber.py

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,28 @@
1-
# custom_power: Lambda function
2-
custom_power = lambda x=0, e=1: x ** e
1+
custom_power_calc = lambda base=0, /, exponent=1: base ** exponent
32

4-
# custom_equation: Function with detailed type annotations and docstring
5-
def custom_equation(
6-
x: int = 0,
7-
y: int = 0,
8-
a: int = 1,
9-
b: int = 1,
10-
*, c: int = 1
11-
) -> float:
3+
def custom_calculation(x:int = 0, y:int = 0, /, a:int = 1, b:int = 1, *, c:int = 1) -> float:
124
"""
13-
Computes the value of the custom equation.
14-
15-
:param x: Positional-only integer, default is 0
16-
:param y: Positional-only integer, default is 0
17-
:param a: Positional-or-keyword integer, default is 1
18-
:param b: Positional-or-keyword integer, default is 1
19-
:param c: Keyword-only integer, default is 1
20-
:return: Float result of the equation (x**a + y**b) / c
21-
"""
22-
return (x**a + y**b) / c
23-
24-
# fn_w_counter: Function with call counting and caller tracking
25-
def fn_w_counter():
26-
"""
27-
Counts the number of times this function is called,
28-
keeping track of caller information.
29-
30-
:return: A tuple of the total number of calls (int) and
31-
a dictionary with caller names and their call counts.
5+
:param x: The positional-only integer base parameter for the equation, default is 0
6+
:param y: The positional-only integer base parameter for the equation, default is 0
7+
:param a: The positional-or-keyword integer exponent parameter for the equation, default is 1
8+
:param b: The positional-or-keyword integer exponent parameter for the equation, default is 1
9+
:param c: The keyword-only integer divisor parameter for the equation, default is 1
10+
:return: The result of the calculation as a float, where the equation is (x**a + y**b) / c
11+
:rtype: float
3212
"""
33-
if not hasattr(fn_w_counter, "call_count"):
34-
fn_w_counter.call_count = 0
35-
fn_w_counter.caller_dict = {}
36-
37-
fn_w_counter.call_count += 1
38-
caller = __name__
39-
if caller not in fn_w_counter.caller_dict:
40-
fn_w_counter.caller_dict[caller] = 0
41-
fn_w_counter.caller_dict[caller] += 1
42-
43-
return fn_w_counter.call_count, fn_w_counter.caller_dict
44-
45-
# Örnek kullanımlar
46-
if __name__ == "__main__":
47-
# custom_power örnekleri
48-
print(custom_power(2)) # 2
49-
print(custom_power(2, 3)) # 8
50-
print(custom_power(2, e=2)) # 4
51-
52-
# custom_equation örnekleri
53-
print(custom_equation(2, 3)) # 5.0
54-
print(custom_equation(2, 3, 2)) # 7.0
55-
print(custom_equation(3, 5, a=2, b=3, c=4)) # 33.5
56-
57-
# fn_w_counter örnekleri
58-
for i in range(10):
59-
fn_w_counter()
13+
return (x ** a + y ** b) / c
14+
15+
def fn_w_counter() -> (int, dict[str, int]):
16+
if not hasattr(fn_w_counter, '_total_calls'):
17+
fn_w_counter._total_calls = 0
18+
fn_w_counter._call_registry = {}
19+
20+
current_caller = __name__
21+
fn_w_counter._total_calls += 1
22+
23+
if current_caller in fn_w_counter._call_registry:
24+
fn_w_counter._call_registry[current_caller] += 1
25+
else:
26+
fn_w_counter._call_registry[current_caller] = 1
27+
28+
return fn_w_counter._total_calls, fn_w_counter._call_registry

0 commit comments

Comments
 (0)