Evaluating more complex arithmetic expression with percentages

  python, python-3.x

I’m evaluating more complex arithmetic expression with percentages, like the examples below:

(5+3)*3%

-5/2+7%+4.5%

4%-15*387-(75/2%)*3+(4-5)+2%

I tried with eval and numexpr and cexprtk but results are incorrect

result=(input("Type the formula: "))
print(eval(result))
print(numexpr.evaluate(result))
print(cexprtk.evaluate_expression(result, {}))

Source: Python Questions

LEAVE A COMMENT