From 21fb8fd905387359a08b2897f1d709499757a374 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 19:38:35 -0700 Subject: [PATCH 01/19] Update flake8_kyu2.yml --- .github/workflows/flake8_kyu2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flake8_kyu2.yml b/.github/workflows/flake8_kyu2.yml index 0ba0c59bfab..191af00eec5 100644 --- a/.github/workflows/flake8_kyu2.yml +++ b/.github/workflows/flake8_kyu2.yml @@ -42,6 +42,6 @@ jobs: # exit-zero treats all errors as warnings. # The GitHub editor is 127 chars wide run: | - flake8 /kyu_2 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics + flake8 kyu_2 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics flake8 . --count --max-complexity=10 --max-line-length=127 --benchmark --show-source --statistics # yamllint enable rule:line-length \ No newline at end of file From fb895ad7b68d1202f479180468b41036fe3ef137 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 19:40:25 -0700 Subject: [PATCH 02/19] Update flake8_kyu2.yml --- .github/workflows/flake8_kyu2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flake8_kyu2.yml b/.github/workflows/flake8_kyu2.yml index 191af00eec5..c38562d8676 100644 --- a/.github/workflows/flake8_kyu2.yml +++ b/.github/workflows/flake8_kyu2.yml @@ -42,6 +42,6 @@ jobs: # exit-zero treats all errors as warnings. # The GitHub editor is 127 chars wide run: | - flake8 kyu_2 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics + flake8 ./kyu_2 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics flake8 . --count --max-complexity=10 --max-line-length=127 --benchmark --show-source --statistics # yamllint enable rule:line-length \ No newline at end of file From b84e12f7495e3620cec98d3bff14e3352d4f2f34 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 19:42:07 -0700 Subject: [PATCH 03/19] Update flake8_kyu2.yml --- .github/workflows/flake8_kyu2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flake8_kyu2.yml b/.github/workflows/flake8_kyu2.yml index c38562d8676..6a3dc675d39 100644 --- a/.github/workflows/flake8_kyu2.yml +++ b/.github/workflows/flake8_kyu2.yml @@ -42,6 +42,6 @@ jobs: # exit-zero treats all errors as warnings. # The GitHub editor is 127 chars wide run: | - flake8 ./kyu_2 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics + flake8 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics ./kyu_2/ flake8 . --count --max-complexity=10 --max-line-length=127 --benchmark --show-source --statistics # yamllint enable rule:line-length \ No newline at end of file From b166e7cc2c9155e6c88036b6eee99063d11a97e4 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 19:44:01 -0700 Subject: [PATCH 04/19] Update flake8_kyu2.yml --- .github/workflows/flake8_kyu2.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/flake8_kyu2.yml b/.github/workflows/flake8_kyu2.yml index 6a3dc675d39..3f848fe08e3 100644 --- a/.github/workflows/flake8_kyu2.yml +++ b/.github/workflows/flake8_kyu2.yml @@ -42,6 +42,6 @@ jobs: # exit-zero treats all errors as warnings. # The GitHub editor is 127 chars wide run: | - flake8 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics ./kyu_2/ - flake8 . --count --max-complexity=10 --max-line-length=127 --benchmark --show-source --statistics + flake8 --count --select=E9,F63,F7,F82 --doctests --show-source --statistics ./kyu_2 + flake8 --count --max-complexity=10 --max-line-length=127 --benchmark --show-source --statistics ./kyu_2 # yamllint enable rule:line-length \ No newline at end of file From 3e6ed65fd7a4be569e573526f0396e98bc018714 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 19:56:15 -0700 Subject: [PATCH 05/19] C901 'normalize_string' is too complex (12) ./kyu_2/evaluate_mathematical_expression/evaluate.py:54:1: C901 'normalize_string' is too complex (12) def normalize_string(string: str) -> str: ^ 1 C901 'normalize_string' is too complex (12) 0.0599 seconds elapsed 152 total logical lines processed 2537 logical lines processed per second 296 total physical lines processed 4941 physical lines processed per second 1607 total tokens processed 26825 tokens processed per second 4 total files processed 66 files processed per second --- .../evaluate.py | 88 ++++++++++--------- .../test_evaluate.py | 3 +- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index ed24d33d52b..c8e2b064624 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -51,48 +51,8 @@ def process_math_expression(string: str, operators: list) -> str: return ' '.join(strings) -def normalize_string(string: str) -> str: - """ - Normalizing string input - :param string: str - :return: str - """ - strings: list = [] - string_temp: str = ''.join([s for s in string if s != ' ']) - - while string_temp != '': - temp: str = '' - - for i, s in enumerate(string_temp): - if s.isdigit(): - temp += s - - if s in '()': - if temp != '': - strings.append(temp) - strings.append(s) - - if i + 1 < len(string_temp): - string_temp = string_temp[i + 1:] - else: - string_temp = '' - break - - if s in OPERATORS: - if temp != '': - strings.append(temp) - strings.append(s) - - if i + 1 < len(string_temp): - string_temp = string_temp[i + 1:] - break - - if i == len(string_temp) - 1: - if temp != '': - strings.append(temp) - string_temp = '' - - return ' '.join([s for s in strings if s != '']) +def condition_checker(): + pass def bracket_start(strings: list) -> int: @@ -199,3 +159,47 @@ def calc(string: str) -> float: string_lst = [float(s) for s in string_lst] string = str(sum(string_lst)) return float(string) + + +def normalize_string(string: str) -> str: + """ + Normalizing string input + :param string: str + :return: str + """ + strings: list = [] + string_temp: str = ''.join([s for s in string if s != ' ']) + + while string_temp != '': + temp: str = '' + + for i, s in enumerate(string_temp): + if s.isdigit(): + temp += s + + if s in '()': + if temp != '': + strings.append(temp) + strings.append(s) + + if i + 1 < len(string_temp): + string_temp = string_temp[i + 1:] + else: + string_temp = '' + break + + if s in OPERATORS: + if temp != '': + strings.append(temp) + strings.append(s) + + if i + 1 < len(string_temp): + string_temp = string_temp[i + 1:] + break + + if i == len(string_temp) - 1: + if temp != '': + strings.append(temp) + string_temp = '' + + return ' '.join([s for s in strings if s != '']) diff --git a/kyu_2/evaluate_mathematical_expression/test_evaluate.py b/kyu_2/evaluate_mathematical_expression/test_evaluate.py index 9851b41495b..cb9f8073717 100644 --- a/kyu_2/evaluate_mathematical_expression/test_evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/test_evaluate.py @@ -78,8 +78,7 @@ def test_calc(self): ['-(-93) / (-36 + 26 + -(18)) + (-7 * -(((-(-67 + -95)))) + -9)', 1121.6785714285713], ['-(-23) + (-4 * -13 + -(1)) - (-30 / (((-(57 + -20)))) + 85)', -11.810810810810807], ['(72) / (-82 - -93 * -(88)) + (-18 - -(((-(60 * 97)))) + -79)', -5917.00871037987], - ['-(77) / (7 * -76 + (59)) + (98 / -(((-(-74 - -47)))) / -5)', 0.8887166236003445] - ) + ['-(77) / (7 * -76 + (59)) + (98 / -(((-(-74 - -47)))) / -5)', 0.8887166236003445]) for string, expected in test_data: From f9e9fd6825d19905ab1bb8d512e5b36c643f4021 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 19:57:24 -0700 Subject: [PATCH 06/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index c8e2b064624..a598a5d88c2 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -51,10 +51,6 @@ def process_math_expression(string: str, operators: list) -> str: return ' '.join(strings) -def condition_checker(): - pass - - def bracket_start(strings: list) -> int: """ Return index of first (open) bracket From 8aa12d9c8d6eb6b0bdd9523c83b66a1547a843d4 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:15:40 -0700 Subject: [PATCH 07/19] Update evaluate.py --- .../evaluate_mathematical_expression/evaluate.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index a598a5d88c2..bffc8e413d3 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -173,11 +173,14 @@ def normalize_string(string: str) -> str: if s.isdigit(): temp += s - if s in '()': - if temp != '': - strings.append(temp) + if (s in '()' or s in OPERATORS or i == len(string_temp) - 1) \ + and temp != '': + strings.append(temp) + + if s in '()' or s in OPERATORS: strings.append(s) + if s in '()': if i + 1 < len(string_temp): string_temp = string_temp[i + 1:] else: @@ -185,17 +188,11 @@ def normalize_string(string: str) -> str: break if s in OPERATORS: - if temp != '': - strings.append(temp) - strings.append(s) - if i + 1 < len(string_temp): string_temp = string_temp[i + 1:] break if i == len(string_temp) - 1: - if temp != '': - strings.append(temp) string_temp = '' return ' '.join([s for s in strings if s != '']) From 752e3ab6d3bf6a4d1266420619535a57b0cd1842 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:23:38 -0700 Subject: [PATCH 08/19] Update evaluate.py --- .../evaluate_mathematical_expression/evaluate.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index bffc8e413d3..a598a5d88c2 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -173,14 +173,11 @@ def normalize_string(string: str) -> str: if s.isdigit(): temp += s - if (s in '()' or s in OPERATORS or i == len(string_temp) - 1) \ - and temp != '': - strings.append(temp) - - if s in '()' or s in OPERATORS: + if s in '()': + if temp != '': + strings.append(temp) strings.append(s) - if s in '()': if i + 1 < len(string_temp): string_temp = string_temp[i + 1:] else: @@ -188,11 +185,17 @@ def normalize_string(string: str) -> str: break if s in OPERATORS: + if temp != '': + strings.append(temp) + strings.append(s) + if i + 1 < len(string_temp): string_temp = string_temp[i + 1:] break if i == len(string_temp) - 1: + if temp != '': + strings.append(temp) string_temp = '' return ' '.join([s for s in strings if s != '']) From e5441c569e0c50fb1dd4bcddc14e1badf4553e77 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:26:17 -0700 Subject: [PATCH 09/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index a598a5d88c2..4d578001574 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -198,4 +198,4 @@ def normalize_string(string: str) -> str: strings.append(temp) string_temp = '' - return ' '.join([s for s in strings if s != '']) + return ' '.join([s for s in strings]) From ab5f5458a859efd92be3c3606d59dbc59ee3ec0b Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:27:39 -0700 Subject: [PATCH 10/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index 4d578001574..44b06f82fa7 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -198,4 +198,4 @@ def normalize_string(string: str) -> str: strings.append(temp) string_temp = '' - return ' '.join([s for s in strings]) + return ' '.join(strings) From 86d1f9b62f2af21678b4f38856b19fa579105623 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:30:42 -0700 Subject: [PATCH 11/19] Update evaluate.py --- .../evaluate.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index 44b06f82fa7..ff6417f107d 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -145,6 +145,7 @@ def calc(string: str) -> float: :param string: str :return: float """ + string = ''.join([s for s in string if s != ' ']) string = normalize_string(string) string = ''.join(string.split('+')) strings: list = string.split() @@ -164,12 +165,11 @@ def normalize_string(string: str) -> str: :return: str """ strings: list = [] - string_temp: str = ''.join([s for s in string if s != ' ']) - while string_temp != '': + while string != '': temp: str = '' - for i, s in enumerate(string_temp): + for i, s in enumerate(string): if s.isdigit(): temp += s @@ -178,10 +178,10 @@ def normalize_string(string: str) -> str: strings.append(temp) strings.append(s) - if i + 1 < len(string_temp): - string_temp = string_temp[i + 1:] + if i + 1 < len(string): + string = string[i + 1:] else: - string_temp = '' + string = '' break if s in OPERATORS: @@ -189,13 +189,13 @@ def normalize_string(string: str) -> str: strings.append(temp) strings.append(s) - if i + 1 < len(string_temp): - string_temp = string_temp[i + 1:] + if i + 1 < len(string): + string = string[i + 1:] break - if i == len(string_temp) - 1: + if i == len(string) - 1: if temp != '': strings.append(temp) - string_temp = '' + string = '' return ' '.join(strings) From 8a8a2486c4f280e80c0676f5622c0d51a2b4de14 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:52:28 -0700 Subject: [PATCH 12/19] Update evaluate.py --- .../evaluate.py | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index ff6417f107d..1bc79d36b28 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -136,7 +136,7 @@ def process_duplicate_minus(string: str) -> str: del strings[i] break - return ' '.join([s for s in strings if s != '']) + return ' '.join(strings) def calc(string: str) -> float: @@ -158,44 +158,56 @@ def calc(string: str) -> float: return float(string) -def normalize_string(string: str) -> str: +def check_conditions(strings, string, temp) -> (str, str): """ - Normalizing string input - :param string: str - :return: str + Check conditions + :param strings: + :param string: + :param temp: + :return: """ - strings: list = [] + for i, s in enumerate(string): + if s.isdigit(): + temp += s - while string != '': - temp: str = '' + if s in '()': + if temp != '': + strings.append(temp) + strings.append(s) - for i, s in enumerate(string): - if s.isdigit(): - temp += s + if i + 1 < len(string): + string = string[i + 1:] + else: + string = '' + break - if s in '()': - if temp != '': - strings.append(temp) - strings.append(s) + if s in OPERATORS: + if temp != '': + strings.append(temp) + strings.append(s) - if i + 1 < len(string): - string = string[i + 1:] - else: - string = '' - break + if i + 1 < len(string): + string = string[i + 1:] + break - if s in OPERATORS: - if temp != '': - strings.append(temp) - strings.append(s) + if i == len(string) - 1: + if temp != '': + strings.append(temp) + string = '' - if i + 1 < len(string): - string = string[i + 1:] - break + return temp, string - if i == len(string) - 1: - if temp != '': - strings.append(temp) - string = '' + +def normalize_string(string: str) -> str: + """ + Normalizing string input + :param string: str + :return: str + """ + strings: list = [] + + while string: + temp: str = '' + temp, string = check_conditions(strings, string, temp) return ' '.join(strings) From c260c5cf4557cd4c6e9880e3841a63c749842795 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:57:43 -0700 Subject: [PATCH 13/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index 1bc79d36b28..9d2ac6dd46d 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -158,7 +158,7 @@ def calc(string: str) -> float: return float(string) -def check_conditions(strings, string, temp) -> (str, str): +def check_conditions(strings, string, temp) -> [str, str]: """ Check conditions :param strings: @@ -170,9 +170,10 @@ def check_conditions(strings, string, temp) -> (str, str): if s.isdigit(): temp += s + if (s in ''.join(OPERATORS) + '()' or i == len(string) - 1) and temp: + strings.append(temp) + if s in '()': - if temp != '': - strings.append(temp) strings.append(s) if i + 1 < len(string): @@ -182,8 +183,6 @@ def check_conditions(strings, string, temp) -> (str, str): break if s in OPERATORS: - if temp != '': - strings.append(temp) strings.append(s) if i + 1 < len(string): @@ -191,8 +190,6 @@ def check_conditions(strings, string, temp) -> (str, str): break if i == len(string) - 1: - if temp != '': - strings.append(temp) string = '' return temp, string From 527229f14db292abdf61ab915ec51b758e343744 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:59:33 -0700 Subject: [PATCH 14/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index 9d2ac6dd46d..f2b24969696 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -158,7 +158,7 @@ def calc(string: str) -> float: return float(string) -def check_conditions(strings, string, temp) -> [str, str]: +def check_conditions(strings, string, temp) -> (str, str): """ Check conditions :param strings: From 4649c74ee6f1c58903a93d719203cfdceeae71b1 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 21:01:53 -0700 Subject: [PATCH 15/19] Update evaluate.py --- .../evaluate.py | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index f2b24969696..87ee10e9781 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -146,7 +146,13 @@ def calc(string: str) -> float: :return: float """ string = ''.join([s for s in string if s != ' ']) - string = normalize_string(string) + + strings: list = [] + while string: + temp: str = '' + temp, string = check_conditions(strings, string, temp) + string = ' '.join(strings) + string = ''.join(string.split('+')) strings: list = string.split() string = process_brackets(strings) @@ -160,7 +166,7 @@ def calc(string: str) -> float: def check_conditions(strings, string, temp) -> (str, str): """ - Check conditions + Checking conditions and normalizing string input :param strings: :param string: :param temp: @@ -193,18 +199,3 @@ def check_conditions(strings, string, temp) -> (str, str): string = '' return temp, string - - -def normalize_string(string: str) -> str: - """ - Normalizing string input - :param string: str - :return: str - """ - strings: list = [] - - while string: - temp: str = '' - temp, string = check_conditions(strings, string, temp) - - return ' '.join(strings) From 73b87dda28c31dd6782047ecb56bddc74e08ebe5 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 21:03:11 -0700 Subject: [PATCH 16/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index 87ee10e9781..dd4160ac220 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -154,7 +154,7 @@ def calc(string: str) -> float: string = ' '.join(strings) string = ''.join(string.split('+')) - strings: list = string.split() + strings = string.split() string = process_brackets(strings) string = process_duplicate_minus(string) string = process_math_expression(string, ['*', '/']) From 6ffe5698b480a554a9b8560232d9983bb8317376 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 21:04:47 -0700 Subject: [PATCH 17/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index dd4160ac220..6791ca9ec26 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -164,13 +164,13 @@ def calc(string: str) -> float: return float(string) -def check_conditions(strings, string, temp) -> (str, str): +def check_conditions(strings: list, string: str, temp: str) -> (str, str): """ - Checking conditions and normalizing string input - :param strings: - :param string: - :param temp: - :return: + Normalizing string input by checking conditions + :param strings: list + :param string: str + :param temp: str + :return: tuple(str, str) """ for i, s in enumerate(string): if s.isdigit(): From cb13be1570fb19a49f052b9a9421340e8cddb7f1 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 21:05:32 -0700 Subject: [PATCH 18/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index 6791ca9ec26..84399f4c70a 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -186,6 +186,7 @@ def check_conditions(strings: list, string: str, temp: str) -> (str, str): string = string[i + 1:] else: string = '' + break if s in OPERATORS: @@ -193,6 +194,7 @@ def check_conditions(strings: list, string: str, temp: str) -> (str, str): if i + 1 < len(string): string = string[i + 1:] + break if i == len(string) - 1: From 25db014a66a3f5f63bbdb31ff9935c54fc1bc8e4 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 21:07:45 -0700 Subject: [PATCH 19/19] Update evaluate.py --- kyu_2/evaluate_mathematical_expression/evaluate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kyu_2/evaluate_mathematical_expression/evaluate.py b/kyu_2/evaluate_mathematical_expression/evaluate.py index 84399f4c70a..6c297d42e48 100644 --- a/kyu_2/evaluate_mathematical_expression/evaluate.py +++ b/kyu_2/evaluate_mathematical_expression/evaluate.py @@ -164,7 +164,7 @@ def calc(string: str) -> float: return float(string) -def check_conditions(strings: list, string: str, temp: str) -> (str, str): +def check_conditions(strings: list, string: str, temp: str) -> tuple[str, str]: """ Normalizing string input by checking conditions :param strings: list @@ -194,7 +194,7 @@ def check_conditions(strings: list, string: str, temp: str) -> (str, str): if i + 1 < len(string): string = string[i + 1:] - + break if i == len(string) - 1: