Calculator: empty-input handling, cleaner results, new operations
#1
by arshvinw5 - opened
What's changed
- Empty inputs: blank fields now show a friendly message instead of a Gradio error.
- Cleaner results: whole numbers show without
.0(5, not5.0), and floating-point noise is rounded away (0.1 + 0.2β0.3). - New operations: power (
^), modulo (mod), square root (β) and percentage (% of, e.g. 15 % of 240 = 36).- The second number field hides when
βis selected. - Clear messages for modulo by zero, negative square roots, results too large to show, and results that aren't real numbers.
- The second number field hides when
demo.launch()now runs only underif __name__ == "__main__":, so tests can import the module.
Tests
- Added
test_calculator.pywith 22 pytest cases covering every operation and error path. 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