Skip to content

Commit

Permalink
Update evaluate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Oct 30, 2024
1 parent 86d1f9b commit 8a8a248
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions kyu_2/evaluate_mathematical_expression/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Check notice on line 172 in kyu_2/evaluate_mathematical_expression/evaluate.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_2/evaluate_mathematical_expression/evaluate.py#L172

Variable name "s" doesn't conform to snake_case naming style (invalid-name)
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)

0 comments on commit 8a8a248

Please sign in to comment.