Skip to content

Commit 9520064

Browse files
authored
Merge pull request #996 from elifyalvac/patch-5
Add custom functions and call counter
2 parents 8b6d7e5 + 0a346b7 commit 9520064

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Week04/functions_elif_yalvac.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 1. custom_power
2+
custom_power = lambda x=0, /, e=1: x ** e
3+
4+
5+
6+
# 2. custom_equation
7+
def custom_equation(x: int = 0, y: int = 0, /,
8+
a: int = 1, b: int = 1, *,
9+
c: int = 1) -> float:
10+
"""
11+
Calculates a specific mathematical expression.
12+
13+
:param x: positional-only integer, default 0
14+
:param y: positional-only integer, default 0
15+
:param a: positional-or-keyword integer, default 1
16+
:param b: positional-or-keyword integer, default 1
17+
:param c: keyword-only integer, default 1
18+
:return: result of (x**a + y**b) / c as float
19+
"""
20+
21+
for val in (x, y, a, b, c):
22+
if not isinstance(val, int):
23+
raise TypeError("must be int")
24+
return (x ** a + y ** b) / c
25+
26+
27+
28+
# 3. fn_w_counter
29+
def fn_w_counter() -> (int, dict[str, int]):
30+
if not hasattr(fn_w_counter, "count"):
31+
fn_w_counter.count = 0
32+
fn_w_counter.count += 1
33+
return fn_w_counter.count, {__name__.split('.')[-1]: fn_w_counter.count}

0 commit comments

Comments
 (0)