Skip to content

Commit 052d196

Browse files
committed
Fixed implicit multiplication
1 parent 68b58c9 commit 052d196

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

final_task/pycalc/calc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,23 @@ def correct_expression(expression):
142142
Returns:
143143
The return list of tokens
144144
"""
145+
res = []
145146
if '()' in expression:
146147
raise CalcError('ERROR: invalid bracket expression')
147148
elif expression == '':
148149
raise CalcError('ERROR: empty expression')
149150
expression = insert_multiplication(match_negative_value(fix_missing_zero(fix_multi_operations(expression))))
150-
regex = re.compile(r'(<=|==|!=|>=|log1p|^-\d+\.\d+|^-\d+|(?<=\W\W)\-\d+\.\d+|(?<=\W\W)\-\d+|'
151+
regex = re.compile(r'(<=|==|!=|>=|e|pi|tau|inf|nan|log1p|^-\d+\.\d+|^-\d+|(?<=\W\W)\-\d+\.\d+|(?<=\W\W)\-\d+|'
151152
r'(?<=\()\-\d+\.\d+|(?<=\()\-\d+|(?<=[a-z]\W)\-\d+\.\d+|(?<=[a-z]\W)\-\d+|(?<=\))\-|'
152153
r'\//|\/|\d+\.\d+|\d+|\W|\w+)')
153154
re_expr = re.split(regex, expression)
154155
re_expr = [x for x in re_expr if x and x != ' ']
156+
for i in reversed(range(len(re_expr))):
157+
if i > 0:
158+
if re_expr[i] == '(' and is_float(re_expr[i - 1]):
159+
re_expr.insert(i, '*')
160+
elif re_expr[i] in constants and re_expr[i - 1] in constants:
161+
re_expr.insert(i, '*')
155162
return re_expr
156163

157164

0 commit comments

Comments
 (0)