From 77b121a019cf9b7ab9a9ca0f89d22fad16203330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emine=20=C3=87etin?= Date: Wed, 7 Jan 2026 18:50:37 +0300 Subject: [PATCH] Implement custom power and equation functions Adds custom power and equation functions with input validation. --- Week04/functions_emine_cetin.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Week04/functions_emine_cetin.py diff --git a/Week04/functions_emine_cetin.py b/Week04/functions_emine_cetin.py new file mode 100644 index 00000000..2a48403f --- /dev/null +++ b/Week04/functions_emine_cetin.py @@ -0,0 +1,25 @@ +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: + """ + Calculates the equation (x**a + y**b) / c. + + :param x: Base for the first term (positional only) + :param y: Base for the second term (positional only) + :param a: Exponent for the first term + :param b: Exponent for the second term + :param c: Divisor (keyword only) + :return: The result as a float + """ + if not all(isinstance(arg, int) for arg in [x, y, a, b, c]): + raise TypeError("All arguments must be integers.") + + return float((x ** a + y ** b) / c) + +_call_count = 0 + +def fn_w_counter() -> (int, dict[str, int]): + global _call_count + _call_count += 1 + + return _call_count, {__name__: _call_count}