From 3dd51e1accb5a65886d5ed80c9d079c4cdab3847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20Yalva=C3=A7?= <59252046+elifyalvac@users.noreply.github.com> Date: Tue, 18 Nov 2025 05:08:31 +0300 Subject: [PATCH] Add custom power and equation functions with counter Added custom power function and custom equation function with detailed docstring. Implemented a call counter function to track total calls and caller counts. --- Week04/functions_elif_yalvac.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Week04/functions_elif_yalvac.py diff --git a/Week04/functions_elif_yalvac.py b/Week04/functions_elif_yalvac.py new file mode 100644 index 00000000..67838e73 --- /dev/null +++ b/Week04/functions_elif_yalvac.py @@ -0,0 +1,30 @@ +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 a specific mathematical expression. + + :param x: Positional-only, default 0 + :param y: Positional-only, default 0 + :param a: Positional or keyword, default 1 + :param b: Positional or keyword, default 1 + :param c: Keyword-only, default 1 + :return: Returns (x**a + y**b) / c as a float + """ + return (x ** a + y ** b) / c + + + + +from collections import defaultdict +import inspect +_total_calls = 0 +_caller_counts = defaultdict(int) +def fn_w_counter() -> tuple[int, dict[str, int]]: + global _total_calls + _total_calls += 1 + caller = inspect.currentframe().f_back.f_globals.get('__name__', '') + _caller_counts[caller] += 1 + return _total_calls, dict(_caller_counts)