Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Week04/functions_feyza_ozdemir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
custom_power = lambda x=0, /, e=1: x ** e


def custom_equation(
x: int = 0,
y: int = 0,
/,
a: int = 1,
b: int = 1,
*,
c: int = 1
) -> float:
"""
This function calculates the result of a custom mathematical equation.

:param x: The first base value (positional-only), defaults to 0.
:type x: int
:param y: The second base value (positional-only), defaults to 0.
:type y: int
:param a: The first exponent (positional-or-keyword), defaults to 1.
:type a: int
:param b: The second exponent (positional-or-keyword), defaults to 1.
:type b: int
:param c: The divisor (keyword-only), defaults to 1.
:type c: int
:return: The result of (x**a + y**b) / c as a float.
:rtype: float
"""
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):
raise TypeError("All parameters must be integers.")

return float((x ** a + y ** b) / c)


def fn_w_counter() -> (int, dict[str, int]):
"""
This function counts total function calls and tracks calls per caller module.

:return: The total call count and a dictionary of caller counts.
:rtype: (int, dict[str, int])
"""
caller = __name__

fn_w_counter.total_calls += 1
fn_w_counter.caller_counts[caller] = fn_w_counter.caller_counts.get(caller, 0) + 1

return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts)


fn_w_counter.total_calls = 0
fn_w_counter.caller_counts = {}
Loading