Calculator: history, live results and expression mode
#2
by arshvinw5 - opened
What's changed
- Expression mode: a new Expression tab that evaluates a whole expression, e.g.
(2 + 3) * 4 / 2β10.- Supports
+ - * /,^/**,mod/%,sqrt(16)/β16, negative numbers,ΓandΓ·. - Evaluated safely with an
astallow-list (noeval). Unsafe or invalid input shows "Invalid expression". - Huge powers (
9^9^9) return "Result is too large" instead of hanging.
- Supports
- Live results: the Calculate button is removed, and results update as you type.
- History panel: Save to history (or Enter) adds entries like
2 + 3 = 5. Newest first, capped at 50, with a Clear history button. Errors and repeats of the latest entry are skipped.
Tests
- 61 tests in
test_calculator.py(39 new). All pass withuv run pytest -q.
How to try it
pip/uv run python gradio_calculator.py, then open http://127.0.0.1:7860