From 67220e4e8b7315f876f95f3cf08b5f60b29b7069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0brahim=20As?= <148447898+zteplez@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:57:02 +0300 Subject: [PATCH] Add custom power and equation functions with counter --- Week04/functions_ibrahim_as.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Week04/functions_ibrahim_as.py diff --git a/Week04/functions_ibrahim_as.py b/Week04/functions_ibrahim_as.py new file mode 100644 index 00000000..68ed21cf --- /dev/null +++ b/Week04/functions_ibrahim_as.py @@ -0,0 +1,22 @@ +import inspect + +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: + return (x ** a + y ** b) / c + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + + # Get the caller's module name + frame = inspect.stack()[1] + caller_name = frame[0].f_globals.get("__name__", "__unknown__") + + # Update call counts + fn_w_counter._total += 1 + fn_w_counter._callers[caller_name] = fn_w_counter._callers.get(caller_name, 0) + 1 + + return (fn_w_counter._total, dict(fn_w_counter._callers)) + +fn_w_counter._total = 0 +fn_w_counter._callers = {}