From 937509d140c6e1c70a54c9012aa63acd012f162b Mon Sep 17 00:00:00 2001 From: gktgkayac <230315009@ogr.cbu.edu.tr> Date: Sat, 14 Nov 2026 20:31:53 +0300 Subject: [PATCH] Implement custom power and equation functions Adds custom power and equation functions with input validation. --- Week04/functions_goktug_kayaci.py | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Week04/functions_goktug_kayaci.py diff --git a/Week04/functions_goktug_kayaci.py b/Week04/functions_goktug_kayaci.py new file mode 100644 index 00000000..372261c4 --- /dev/null +++ b/Week04/functions_goktug_kayaci.py @@ -0,0 +1,34 @@ +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 result of the equation (x**a + y**b) / c. + + :param x: First base, positional-only + :param y: Second base, positional-only + :param a: Exponent of x + :param b: Exponent of y + :param c: Divisor, keyword-only + :return: Result of the equation as a float + """ + for name, value in (("x", x), ("y", y), ("a", a), ("b", b), ("c", c)): + if not isinstance(value, int): + raise TypeError(f"{name} must be an integer") + + if c == 0: + raise ValueError("c cannot be zero") + + return float((x ** a + y ** b) / c) + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, "total"): + fn_w_counter.total = 0 + fn_w_counter.callers = {} + + fn_w_counter.total += 1 + + fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1 + + return fn_w_counter.total, fn_w_counter.callers.copy()