An easily extendable python calculator that evaluates a formula given as string. It supports a wide variety of commonly used operations:
- basic operators:
+,-,*,/,//,%,^ - constants:
e,pi - unary functions:
ceil,floor,ln(basee),log(base10),sqrt - trigonometric functions:
sin,cos,tan,asin,acos,atan
It maintains the operator precedence,
e.g., it will always multiply terms if possible before adding others. Integers, floats and values
in scientific notation (e.g., 1e-3 for 0.001) are all supported.
Moreover, more may be easily added by appending them on top of the main file in the respective sections.
- Install it as usual with
pip:
python -m pip install git+https://github.com/tigxy/pycalc.git - Or from source:
python -m pip install .
- Either from the command line:
python -m pycalc "2+2" - Or inside your code
from pycalc import solve
result = solve("2 + 2")
print(result) # 4.0Mostly a fun little side project as I have been wondering how to best parse and evaluate a mathematical formula. In case you have any real use-case, please let me know!
Feel free to create an issue or a PR in case you would like some additional functionality.
MIT License - see the LICENSE file for more details.