MathREPL, a math expression evaluator using Python eval()
and the math
module.
MathREPL is an attempt to show how to use Python eval()
to solve real-world problems while minimizing (but not removing) its security issues. So, the most important piece of code in this application is the function evaluate()
which lives in the evaluator
module.
MathREPL is a sample project based on the example I used in my Real Python tutorial: Python eval(): Evaluate Expressions Dynamically.
- Clone the repo (
git clone https://github.com/lpozo/mathrepl.git
) cd
into the directory of the repo (cd mathrepl
)- Run the main script (
python3 main.py
)
The steps in the previous section will preset you with a prompt like this:
MathREPL 1.0, your Python math expressions evaluator!
Enter a valid math expression after the prompt "mr>>".
Type "help" for more information.
Type "quit" or "exit" to exit.
mr>>
At mr>>
type any math expression that follows Python syntax and uses the functionalities defined in the Python math
module. For example:
mr>> (5 + 7) / 2
6.0
mr>> sqrt(pow(10, 2) + pow(15, 2))
18.027756377319946
mr>>
- Version 1.0
- Include basic functionalities to evaluate math-related expressions with Python
eval()
function and themath
module.
- Include basic functionalities to evaluate math-related expressions with Python
- Fork MathREPL from (https://github.com/lpozo/mathrepl/fork)
- Clone your fork locally (
git clone https://github.com/your_user_name/mathrepl.git
) - Create your feature branch (
git checkout -b feature_awesome_feature
) - Commit your changes (
git commit -am 'Add some awesome feature'
) - Push to the branch (
git push -u origin feature_awesome_feature
) - Create a new Pull Request against the
develop
branch of MathREPL - Wait for code review and feedback
You can run the tests for MathREPL using pytest
. To do this, just open a command-line in MathREPL's root directory and run the following command:
$ pytest -v tests
You might need to include the current directory (.
) in your Python path (PYTHONPATH
) for this to work. A fast way to do that is by typing the following command in your command-line:
$ export PYTHONPATH="$PYTHONPATH:."
Leodanis Pozo Ramos – Twitter: @lpozo78 – E-mail: [email protected]
MathREPL is distributed under the MIT license. See LICENSE for more information.