0

I am accepting user input in ascii math notation and need to evaluate that input in python with help from the sympy library.

For example, a user might input:

2x^2

My understanding is that to evaluate this function in python, it would need to be in format:

2*x**2

My thought is that there must already be some libraries out there that could help with notation conversion but I have been unable to find any... Any suggestions would be greatly appreciated.

1

1 Answer 1

1

The parse_expr function will help:

>>> from sympy.parsing.sympy_parser import (parse_expr, convert_xor, 
    standard_transformations, implicit_multiplication)
>>> parse_expr('2x^2',transformations=standard_transformations+
... (convert_xor,implicit_multiplication))
2*x**2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.