Skip to content

Commit 61bb08e

Browse files
authored
Add custom power and equation functions with call counter
This file defines a custom power function and a custom equation function that performs calculations based on provided integer parameters. It also includes a function to count calls to it.
1 parent 71f5b39 commit 61bb08e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Week04/functions_tarik_bozgan.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# custom_power (lambda)
2+
custom_power = lambda x=0, e=1: x ** e
3+
4+
5+
def custom_equation(
6+
x: int = 0,
7+
y: int = 0,
8+
a: int = 1,
9+
b: int = 1,
10+
*,
11+
c: int = 1
12+
) -> float:
13+
"""
14+
:param x: integer value
15+
:param y: integer value
16+
:param a: integer value
17+
:param b: integer value
18+
:param c: integer value
19+
:return: result of equation
20+
"""
21+
if not all(isinstance(v, int) for v in (x, y, a, b, c)):
22+
raise TypeError("All parameters must be int")
23+
24+
return (x ** a + y ** b) / c
25+
26+
27+
_call_count = 0
28+
29+
def fn_w_counter() -> (int, dict[str, int]):
30+
global _call_count
31+
_call_count += 1
32+
return _call_count, {__name__: _call_count}

0 commit comments

Comments
 (0)