From 40166c26ca08e43976b4baa7bfa9c05949f28160 Mon Sep 17 00:00:00 2001 From: ezberaysegul <105494369+ezberaysegul@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:47:01 +0300 Subject: [PATCH 1/3] Create functions_aysegul_ezber.py --- Week04/functions_aysegul_ezber.py | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Week04/functions_aysegul_ezber.py diff --git a/Week04/functions_aysegul_ezber.py b/Week04/functions_aysegul_ezber.py new file mode 100644 index 00000000..742c78c9 --- /dev/null +++ b/Week04/functions_aysegul_ezber.py @@ -0,0 +1,59 @@ +# custom_power: Lambda function +custom_power = lambda x=0, e=1: x ** e + +# custom_equation: Function with detailed type annotations and docstring +def custom_equation( + x: int = 0, + y: int = 0, + a: int = 1, + b: int = 1, + *, c: int = 1 +) -> float: + """ + Computes the value of the custom equation. + + :param x: Positional-only integer, default is 0 + :param y: Positional-only integer, default is 0 + :param a: Positional-or-keyword integer, default is 1 + :param b: Positional-or-keyword integer, default is 1 + :param c: Keyword-only integer, default is 1 + :return: Float result of the equation (x**a + y**b) / c + """ + return (x**a + y**b) / c + +# fn_w_counter: Function with call counting and caller tracking +def fn_w_counter(): + """ + Counts the number of times this function is called, + keeping track of caller information. + + :return: A tuple of the total number of calls (int) and + a dictionary with caller names and their call counts. + """ + if not hasattr(fn_w_counter, "call_count"): + fn_w_counter.call_count = 0 + fn_w_counter.caller_dict = {} + + fn_w_counter.call_count += 1 + caller = __name__ + if caller not in fn_w_counter.caller_dict: + fn_w_counter.caller_dict[caller] = 0 + fn_w_counter.caller_dict[caller] += 1 + + return fn_w_counter.call_count, fn_w_counter.caller_dict + +# Örnek kullanımlar +if __name__ == "__main__": + # custom_power örnekleri + print(custom_power(2)) # 2 + print(custom_power(2, 3)) # 8 + print(custom_power(2, e=2)) # 4 + + # custom_equation örnekleri + print(custom_equation(2, 3)) # 5.0 + print(custom_equation(2, 3, 2)) # 7.0 + print(custom_equation(3, 5, a=2, b=3, c=4)) # 33.5 + + # fn_w_counter örnekleri + for i in range(10): + fn_w_counter() From 7c4f3a97398da09078a95fd5b3fb052570176a0e Mon Sep 17 00:00:00 2001 From: ezberaysegul <105494369+ezberaysegul@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:51:46 +0300 Subject: [PATCH 2/3] Update functions_aysegul_ezber.py --- Week04/functions_aysegul_ezber.py | 81 ++++++++++--------------------- 1 file changed, 25 insertions(+), 56 deletions(-) diff --git a/Week04/functions_aysegul_ezber.py b/Week04/functions_aysegul_ezber.py index 742c78c9..e3718269 100644 --- a/Week04/functions_aysegul_ezber.py +++ b/Week04/functions_aysegul_ezber.py @@ -1,59 +1,28 @@ -# custom_power: Lambda function -custom_power = lambda x=0, e=1: x ** e +custom_power_calc = lambda base=0, /, exponent=1: base ** exponent -# custom_equation: Function with detailed type annotations and docstring -def custom_equation( - x: int = 0, - y: int = 0, - a: int = 1, - b: int = 1, - *, c: int = 1 -) -> float: +def custom_calculation(x:int = 0, y:int = 0, /, a:int = 1, b:int = 1, *, c:int = 1) -> float: """ - Computes the value of the custom equation. - - :param x: Positional-only integer, default is 0 - :param y: Positional-only integer, default is 0 - :param a: Positional-or-keyword integer, default is 1 - :param b: Positional-or-keyword integer, default is 1 - :param c: Keyword-only integer, default is 1 - :return: Float result of the equation (x**a + y**b) / c - """ - return (x**a + y**b) / c - -# fn_w_counter: Function with call counting and caller tracking -def fn_w_counter(): - """ - Counts the number of times this function is called, - keeping track of caller information. - - :return: A tuple of the total number of calls (int) and - a dictionary with caller names and their call counts. + :param x: The positional-only integer base parameter for the equation, default is 0 + :param y: The positional-only integer base parameter for the equation, default is 0 + :param a: The positional-or-keyword integer exponent parameter for the equation, default is 1 + :param b: The positional-or-keyword integer exponent parameter for the equation, default is 1 + :param c: The keyword-only integer divisor parameter for the equation, default is 1 + :return: The result of the calculation as a float, where the equation is (x**a + y**b) / c + :rtype: float """ - if not hasattr(fn_w_counter, "call_count"): - fn_w_counter.call_count = 0 - fn_w_counter.caller_dict = {} - - fn_w_counter.call_count += 1 - caller = __name__ - if caller not in fn_w_counter.caller_dict: - fn_w_counter.caller_dict[caller] = 0 - fn_w_counter.caller_dict[caller] += 1 - - return fn_w_counter.call_count, fn_w_counter.caller_dict - -# Örnek kullanımlar -if __name__ == "__main__": - # custom_power örnekleri - print(custom_power(2)) # 2 - print(custom_power(2, 3)) # 8 - print(custom_power(2, e=2)) # 4 - - # custom_equation örnekleri - print(custom_equation(2, 3)) # 5.0 - print(custom_equation(2, 3, 2)) # 7.0 - print(custom_equation(3, 5, a=2, b=3, c=4)) # 33.5 - - # fn_w_counter örnekleri - for i in range(10): - fn_w_counter() + return (x ** a + y ** b) / c + +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter, '_total_calls'): + fn_w_counter._total_calls = 0 + fn_w_counter._call_registry = {} + + current_caller = __name__ + fn_w_counter._total_calls += 1 + + if current_caller in fn_w_counter._call_registry: + fn_w_counter._call_registry[current_caller] += 1 + else: + fn_w_counter._call_registry[current_caller] = 1 + + return fn_w_counter._total_calls, fn_w_counter._call_registry From 25c49c46d69baad80ac5a026ef4c89e0c38aaaa0 Mon Sep 17 00:00:00 2001 From: ezberaysegul <105494369+ezberaysegul@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:53:53 +0300 Subject: [PATCH 3/3] Update functions_aysegul_ezber.py --- Week04/functions_aysegul_ezber.py | 41 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/Week04/functions_aysegul_ezber.py b/Week04/functions_aysegul_ezber.py index e3718269..c9304a84 100644 --- a/Week04/functions_aysegul_ezber.py +++ b/Week04/functions_aysegul_ezber.py @@ -1,28 +1,27 @@ -custom_power_calc = lambda base=0, /, exponent=1: base ** exponent -def custom_calculation(x:int = 0, y:int = 0, /, a:int = 1, b:int = 1, *, c:int = 1) -> float: +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: """ - :param x: The positional-only integer base parameter for the equation, default is 0 - :param y: The positional-only integer base parameter for the equation, default is 0 - :param a: The positional-or-keyword integer exponent parameter for the equation, default is 1 - :param b: The positional-or-keyword integer exponent parameter for the equation, default is 1 - :param c: The keyword-only integer divisor parameter for the equation, default is 1 - :return: The result of the calculation as a float, where the equation is (x**a + y**b) / c + :param x: The positional-only integer base parameter for the equation , default is 0 + :param y: The positional-only integer base parameter for the equation , default is 0 + :param a: The positional-or-keyword integer exponent parameter for the equation , default is 1 + :param b: The positional-or-keyword integer exponent parameter for the equation , default is 1 + :param c: The keyword-only integer divisor parameter for the equation , default is 1 + :return: The result of the calculation as a float and the equation is (x**a + y**b)/c :rtype: float """ - return (x ** a + y ** b) / c + return (x**a + y**b)/c def fn_w_counter() -> (int, dict[str, int]): - if not hasattr(fn_w_counter, '_total_calls'): - fn_w_counter._total_calls = 0 - fn_w_counter._call_registry = {} - - current_caller = __name__ - fn_w_counter._total_calls += 1 - - if current_caller in fn_w_counter._call_registry: - fn_w_counter._call_registry[current_caller] += 1 + if not hasattr(fn_w_counter,'_call_counter'): + fn_w_counter._call_counter = 0 + fn_w_counter._caller_dict = {} + caller = __name__ + fn_w_counter._call_counter += 1 + if caller in fn_w_counter._caller_dict: + fn_w_counter._caller_dict[caller] += 1 else: - fn_w_counter._call_registry[current_caller] = 1 - - return fn_w_counter._total_calls, fn_w_counter._call_registry + fn_w_counter._caller_dict[caller] = 1 + return fn_w_counter._call_counter,fn_w_counter._caller_dict