From 1626226fb199e47020d86f9186f9703370870b96 Mon Sep 17 00:00:00 2001 From: zeynep nur erten Date: Tue, 24 Mar 2026 12:37:23 +0300 Subject: [PATCH 1/5] Add custom power and equation functions Implement custom power and equation functions with a call counter. --- Week04/functions_zeynepnur_erten.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Week04/functions_zeynepnur_erten.py diff --git a/Week04/functions_zeynepnur_erten.py b/Week04/functions_zeynepnur_erten.py new file mode 100644 index 00000000..88f76a59 --- /dev/null +++ b/Week04/functions_zeynepnur_erten.py @@ -0,0 +1,27 @@ + +custom_power = lambda x=0,/, e=1 : x ** e + + +def custom_equation(int x, int y, /, int a, int b,*, int c) -> float : + """ + This function returns the result of an operation based on the specified base and exponent values. + + :param x: First base value + :param y: Second base value + :param a: First exponent value + :param b: Second exponent value + :param c: Divisor value + :return: (x*a + y*b)/c + """ + return (x**a + y**b)/c + + +calls = 0 +def fn_w_counter: + global calls, + calls += 1 + return (calls, {__name__: calls }) + + + + From 56671192a4359e91bbad0745b8599f9357eec150 Mon Sep 17 00:00:00 2001 From: zeynep nur erten Date: Tue, 24 Mar 2026 12:40:41 +0300 Subject: [PATCH 2/5] Fix function definition and return statement in fn_w_counter --- Week04/functions_zeynepnur_erten.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week04/functions_zeynepnur_erten.py b/Week04/functions_zeynepnur_erten.py index 88f76a59..28ebed99 100644 --- a/Week04/functions_zeynepnur_erten.py +++ b/Week04/functions_zeynepnur_erten.py @@ -17,10 +17,10 @@ def custom_equation(int x, int y, /, int a, int b,*, int c) -> float : calls = 0 -def fn_w_counter: +def fn_w_counter()->(int, dict[str, int]): global calls, calls += 1 - return (calls, {__name__: calls }) + return calls, {__name__: calls } From c4660b8c5303d10e1562c88cbf5fdd2f167f1e45 Mon Sep 17 00:00:00 2001 From: zeynep nur erten Date: Tue, 24 Mar 2026 12:42:57 +0300 Subject: [PATCH 3/5] Refactor custom_equation parameter type hints Updated type hints for function parameters in custom_equation. --- Week04/functions_zeynepnur_erten.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_zeynepnur_erten.py b/Week04/functions_zeynepnur_erten.py index 28ebed99..0602e00f 100644 --- a/Week04/functions_zeynepnur_erten.py +++ b/Week04/functions_zeynepnur_erten.py @@ -2,7 +2,7 @@ custom_power = lambda x=0,/, e=1 : x ** e -def custom_equation(int x, int y, /, int a, int b,*, int c) -> float : +def custom_equation(x: int , y: int , /, a: int, b: int , * , c: int) -> float : """ This function returns the result of an operation based on the specified base and exponent values. From f08019cd149fd638cfaace49e5ce513382ce190c Mon Sep 17 00:00:00 2001 From: zeynep nur erten Date: Tue, 24 Mar 2026 12:45:32 +0300 Subject: [PATCH 4/5] Modify custom_equation defaults and global calls Updated default parameter values for custom_equation function and fixed global variable declaration. --- Week04/functions_zeynepnur_erten.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week04/functions_zeynepnur_erten.py b/Week04/functions_zeynepnur_erten.py index 0602e00f..fe430924 100644 --- a/Week04/functions_zeynepnur_erten.py +++ b/Week04/functions_zeynepnur_erten.py @@ -2,7 +2,7 @@ custom_power = lambda x=0,/, e=1 : x ** e -def custom_equation(x: int , y: int , /, a: int, b: int , * , c: int) -> float : +def custom_equation(x: int = 0 , y: int = 0 , /, a: int = 1, b: int=1 , * , c: int = 1) -> float : """ This function returns the result of an operation based on the specified base and exponent values. @@ -18,7 +18,7 @@ def custom_equation(x: int , y: int , /, a: int, b: int , * , c: int) -> float calls = 0 def fn_w_counter()->(int, dict[str, int]): - global calls, + global calls calls += 1 return calls, {__name__: calls } From 0b19ab5566949ab3d0c967f83cdc491365c67346 Mon Sep 17 00:00:00 2001 From: zeynep nur erten Date: Mon, 30 Mar 2026 19:43:13 +0300 Subject: [PATCH 5/5] Refactor fn_w_counter to use function attributes --- Week04/functions_zeynepnur_erten.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Week04/functions_zeynepnur_erten.py b/Week04/functions_zeynepnur_erten.py index fe430924..0cfc474e 100644 --- a/Week04/functions_zeynepnur_erten.py +++ b/Week04/functions_zeynepnur_erten.py @@ -16,11 +16,13 @@ def custom_equation(x: int = 0 , y: int = 0 , /, a: int = 1, b: int=1 , * , c: i return (x**a + y**b)/c -calls = 0 -def fn_w_counter()->(int, dict[str, int]): - global calls - calls += 1 - return calls, {__name__: calls } +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter, "calls"): + fn_w_counter.calls = 0 + + fn_w_counter.calls += 1 + + return fn_w_counter.calls, {__name__: fn_w_counter.calls}