larzcalc
A calculator that explains itself.
larzcalc safely evaluates arithmetic (no eval - it tokenizes and evaluates by hand) and, the point, explains the order of operations step by step, so a learner sees why 2 + 3 * 4 is 14 and not 20. A tiny expression interpreter you can read.
larzscript pkg install calc
What you get
- evaluate() with correct precedence
- explain() the order of operations
- No eval - a real tiny interpreter
- See how tokenizing + parsing work
Try it
import "calc" as calc
print(calc.evaluate("2 + 3 * 4"))
print(calc.evaluate("(2 + 3) * 4"))
print(calc.evaluate("2 ^ 3 ^ 2"))
print(calc.explain("2 + 3 * 4"))Output
14 20 512 (2 + (3 * 4)) = 14
Why it's in the Larz Stack
larzcalc is a real Larzscript package (larzscript pkg install calc) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.