From 9d7c09743d979911a97dbd936a85db0636209849 Mon Sep 17 00:00:00 2001 From: busedemirbass Date: Wed, 15 Apr 2026 09:20:37 +0300 Subject: [PATCH 1/3] Create functions_buse_demirbas --- Week04/functions_buse_demirbas | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Week04/functions_buse_demirbas diff --git a/Week04/functions_buse_demirbas b/Week04/functions_buse_demirbas new file mode 100644 index 00000000..2580502b --- /dev/null +++ b/Week04/functions_buse_demirbas @@ -0,0 +1,47 @@ +exec("custom_power = lambda x=0, /, e=1: x ** e", globals()) + +_counter = {} + +def _make_custom_equation(): + src = ''' +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: + """ + Computes (x**a + y**b) / c. + + :param x: Base for the first term. Default 0. + :type x: int + :param y: Base for the second term. Default 0. + :type y: int + :param a: Exponent for x. Default 1. + :type a: int + :param b: Exponent for y. Default 1. + :type b: int + :param c: Divisor. Default 1. + :type c: int + :return: The result of (x**a + y**b) / c. + :rtype: float + """ + if not isinstance(x, int) or not isinstance(y, int): + raise TypeError("x and y must be integers") + if not isinstance(a, int) or not isinstance(b, int) or not isinstance(c, int): + raise TypeError("a, b and c must be integers") + return (x ** a + y ** b) / c +''' + ns = {} + exec(src, ns) + return ns["custom_equation"] + +custom_equation = _make_custom_equation() + +def _make_fn_w_counter(): + src = ''' +def fn_w_counter() -> (int, dict[str, int]): + _counter[__name__] = _counter.get(__name__, 0) + 1 + total = _counter[__name__] + return (total, {__name__: total}) +''' + ns = {"_counter": _counter, "__name__": __name__} + exec(src, ns) + return ns["fn_w_counter"] + +fn_w_counter = _make_fn_w_counter() From f48a51d26de9fc01880d72efc01c52dc5db13c56 Mon Sep 17 00:00:00 2001 From: busedemirbass Date: Wed, 15 Apr 2026 09:28:07 +0300 Subject: [PATCH 2/3] Update functions_buse_demirbas --- Week04/functions_buse_demirbas | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Week04/functions_buse_demirbas b/Week04/functions_buse_demirbas index 2580502b..4f16a62e 100644 --- a/Week04/functions_buse_demirbas +++ b/Week04/functions_buse_demirbas @@ -1,6 +1,5 @@ exec("custom_power = lambda x=0, /, e=1: x ** e", globals()) -_counter = {} def _make_custom_equation(): src = ''' @@ -31,17 +30,21 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int exec(src, ns) return ns["custom_equation"] + custom_equation = _make_custom_equation() + def _make_fn_w_counter(): + counter = {} src = ''' def fn_w_counter() -> (int, dict[str, int]): - _counter[__name__] = _counter.get(__name__, 0) + 1 - total = _counter[__name__] + counter[__name__] = counter.get(__name__, 0) + 1 + total = counter[__name__] return (total, {__name__: total}) ''' - ns = {"_counter": _counter, "__name__": __name__} + ns = {"counter": counter, "__name__": __name__} exec(src, ns) return ns["fn_w_counter"] + fn_w_counter = _make_fn_w_counter() From 3f88dd39dc4aa5d2607b674eecdaa97e6524ec7a Mon Sep 17 00:00:00 2001 From: busedemirbass Date: Wed, 15 Apr 2026 09:32:37 +0300 Subject: [PATCH 3/3] Update functions_buse_demirbas --- Week04/functions_buse_demirbas | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/Week04/functions_buse_demirbas b/Week04/functions_buse_demirbas index 4f16a62e..ce1c4222 100644 --- a/Week04/functions_buse_demirbas +++ b/Week04/functions_buse_demirbas @@ -1,8 +1,6 @@ exec("custom_power = lambda x=0, /, e=1: x ** e", globals()) -def _make_custom_equation(): - src = ''' def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: """ Computes (x**a + y**b) / c. @@ -25,26 +23,11 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int if not isinstance(a, int) or not isinstance(b, int) or not isinstance(c, int): raise TypeError("a, b and c must be integers") return (x ** a + y ** b) / c -''' - ns = {} - exec(src, ns) - return ns["custom_equation"] -custom_equation = _make_custom_equation() +_counter = {} - -def _make_fn_w_counter(): - counter = {} - src = ''' def fn_w_counter() -> (int, dict[str, int]): - counter[__name__] = counter.get(__name__, 0) + 1 - total = counter[__name__] + _counter[__name__] = _counter.get(__name__, 0) + 1 + total = _counter[__name__] return (total, {__name__: total}) -''' - ns = {"counter": counter, "__name__": __name__} - exec(src, ns) - return ns["fn_w_counter"] - - -fn_w_counter = _make_fn_w_counter()