Skip to content

Commit 01cb8c7

Browse files
authored
Create functions_burakcan_aksoy.py
1 parent 71f5b39 commit 01cb8c7

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Week04/functions_burakcan_aksoy.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# custom_power: A lambda function
2+
# - Two parameters (x and e)
3+
# - x is positional-only
4+
# - e is positional-or-keyword
5+
# - x has default value 0
6+
# - e has default value 1
7+
# - Returns x**e
8+
custom_power = lambda x=0, /, e=1: x ** e
9+
10+
11+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
12+
"""
13+
A custom equation that calculates (x**a + y**b) / c
14+
15+
:param x: First integer value (positional-only, default 0)
16+
:param y: Second integer value (positional-only, default 0)
17+
:param a: Exponent for x (positional-or-keyword, default 1)
18+
:param b: Exponent for y (positional-or-keyword, default 1)
19+
:param c: Divisor (keyword-only, default 1)
20+
:return: The result of (x**a + y**b) / c as a float
21+
"""
22+
# Type checking
23+
if not isinstance(x, int) or isinstance(x, bool):
24+
raise TypeError("x must be an integer")
25+
if not isinstance(y, int) or isinstance(y, bool):
26+
raise TypeError("y must be an integer")
27+
if not isinstance(a, int) or isinstance(a, bool):
28+
raise TypeError("a must be an integer")
29+
if not isinstance(b, int) or isinstance(b, bool):
30+
raise TypeError("b must be an integer")
31+
if not isinstance(c, int) or isinstance(c, bool):
32+
raise TypeError("c must be an integer")
33+
34+
return (x ** a + y ** b) / c
35+
36+
37+
# fn_w_counter: A function that counts calls
38+
# - Returns a tuple of (call_count, {module_name: call_count})
39+
# - Uses a closure to maintain state
40+
_counter = 0
41+
_module_name = __name__
42+
43+
def fn_w_counter() -> (int, dict[str, int]):
44+
"""
45+
A function that counts the number of times it has been called.
46+
47+
:return: A tuple containing the call count and a dictionary with module info
48+
"""
49+
global _counter
50+
_counter += 1
51+
return (_counter, {_module_name: _counter})

0 commit comments

Comments
 (0)