Skip to content

Commit 13c8c77

Browse files
authored
Merge pull request canbula#779 from feyza-ozdemir/week04-func
Add Week04 functions assignment - Feyza
2 parents fc3e256 + 1c849ec commit 13c8c77

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎Week04/functions_feyza_ozdemir.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
custom_power = lambda x=0, /, e=1: x ** e
2+
3+
4+
def custom_equation(
5+
x: int = 0,
6+
y: int = 0,
7+
/,
8+
a: int = 1,
9+
b: int = 1,
10+
*,
11+
c: int = 1
12+
) -> float:
13+
"""
14+
This function calculates the result of a custom mathematical equation.
15+
16+
:param x: The first base value (positional-only), defaults to 0.
17+
:type x: int
18+
:param y: The second base value (positional-only), defaults to 0.
19+
:type y: int
20+
:param a: The first exponent (positional-or-keyword), defaults to 1.
21+
:type a: int
22+
:param b: The second exponent (positional-or-keyword), defaults to 1.
23+
:type b: int
24+
:param c: The divisor (keyword-only), defaults to 1.
25+
:type c: int
26+
:return: The result of (x**a + y**b) / c as a float.
27+
:rtype: float
28+
"""
29+
if not (type(x) is int and type(y) is int and type(a) is int and type(b) is int and type(c) is int):
30+
raise TypeError("All parameters must be integers.")
31+
32+
return float((x ** a + y ** b) / c)
33+
34+
35+
def fn_w_counter() -> (int, dict[str, int]):
36+
"""
37+
This function counts total function calls and tracks calls per caller module.
38+
39+
:return: The total call count and a dictionary of caller counts.
40+
:rtype: (int, dict[str, int])
41+
"""
42+
caller = __name__
43+
44+
fn_w_counter.total_calls += 1
45+
fn_w_counter.caller_counts[caller] = fn_w_counter.caller_counts.get(caller, 0) + 1
46+
47+
return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts)
48+
49+
50+
fn_w_counter.total_calls = 0
51+
fn_w_counter.caller_counts = {}

0 commit comments

Comments
 (0)