From 36deab129d35263b3ad61afd55a4aaa0e13b7bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berra=20S=C3=96YLER?= <118564672+berriesyl@users.noreply.github.com> Date: Sat, 2 Nov 2024 13:26:57 +0300 Subject: [PATCH] Create functions_berra_soyler.py --- Week04/functions_berra_soyler.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Week04/functions_berra_soyler.py diff --git a/Week04/functions_berra_soyler.py b/Week04/functions_berra_soyler.py new file mode 100644 index 00000000..646316fb --- /dev/null +++ b/Week04/functions_berra_soyler.py @@ -0,0 +1,28 @@ +from typing import Callable, Tuple, Dict + +custom_power: Callable[[int, int], int] = 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: + """ + Compute a custom equation. + + :param x: An integer, positional-only, with default value 0 + :param y: An integer, positional-only, with default value 0 + :param a: An integer, positional-or-keyword, with default value 1 + :param b: An integer, positional-or-keyword, with default value 1 + :param c: An integer, keyword-only, with default value 1 + :return: Result of (x**a + y**b) / c as a float + """ + return (x ** a + y ** b) / c + +call_counter: Dict[str, int] = {} + +def fn_w_counter() -> Tuple[int, Dict[str, int]]: + """ + Count the number of function calls and return caller information. + + :return: A tuple containing the total number of calls and a dictionary with caller names as keys and call counts as values. + """ + caller = "__main__" + call_counter[caller] = call_counter.get(caller, 0) + 1 + return call_counter[caller], call_counter