← All posts

Math Tools CLI: 12 Calculators in One Terminal Window

2023Python · CLI

A terminal menu with 12 options. Area of a circle. Matrix determinant. Quadratic roots. Prime check. Function graphing. Each one is a separate function, and most are three lines of math plus a print statement. The project is not deep. It is wide.

Twelve Independent Calculators

Area, volume, surface area, trig functions, hypotenuse, scientific calculator, factorial, logarithms, matrix operations, primality testing, quadratic solving, unit conversion, and graphing. Each lives in its own function and shares nothing with the others. No state, no dependencies between them, no shared data. Pick a number, enter some values, get an answer, return to the menu.

The matrix operations use NumPy because implementing matrix multiplication and inversion from scratch is error prone. The graphing function uses Matplotlib to plot over a fixed domain from negative ten to positive eleven. Everything else uses the math module and basic arithmetic.

The eval Decision

The scientific calculator accepts arbitrary expressions and evaluates them using Python eval with a restricted namespace. Builtins are disabled. Only the math module functions are accessible. No file access, no system calls, no way to do anything except compute trigonometric expressions and arithmetic.

It is still eval. A determined user could probably find a way around the restriction. But for a CLI tool intended to run on my own machine, the convenience of typing sin(pi/4)*2 and getting a result outweighs the theoretical risk. I would not ship this to other people without replacing eval with a proper parser.

What Is Missing

None of the functions validate input. Enter a letter where a number is expected and the program crashes. Enter a negative number for a logarithm and it crashes. Enter nothing at all and it crashes. The graphing function also uses eval without the same restrictions as the scientific calculator, which is inconsistent.

There is no way to save results, no way to graph over a custom range, no way to chain calculations. Every operation starts fresh.

Coverage is not depth. The project touches geometry, linear algebra, number theory, and calculus preparation. None of them go far enough to be genuinely useful on their own. The value is having all of them in one place with one interface.

View all projects →View on GitHub ↗