From c260c5cf4557cd4c6e9880e3841a63c749842795 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Tue, 29 Oct 2024 20:57:43 -0700 Subject: [PATCH] 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