A simple command-line calculator written in Python. This project demonstrates how to safely evaluate mathematical expressions
from user input without using the dangerous eval() function, which can lead to security vulnerabilities.
- Safe Evaluation: Parses expressions using the
ast(Abstract Syntax Tree) module to ensure only numeric and supported mathematical operations are executed. - CLI Mode: Evaluate a single expression directly from the command line.
- REPL Mode: An interactive Read-Eval-Print Loop for continuous calculations.
- Make sure you have Python installed.
- Save the code in a file named
safe_eval.py. - Run from the terminal:
python safe_eval.py "2 + 3 * 4"