Skip to content

CLI calculator added (add/sub/mul/div)#687

Open
opencode-agent[bot] wants to merge 1 commit into
mainfrom
opencode/issue685-20260330004523
Open

CLI calculator added (add/sub/mul/div)#687
opencode-agent[bot] wants to merge 1 commit into
mainfrom
opencode/issue685-20260330004523

Conversation

@opencode-agent
Copy link
Copy Markdown

Implemented a minimal CLI calculator and added it to the repository.

What I added

  • calculator.py at the repository root
    • Supports operations: add, subtract, multiply, divide
    • CLI usage: python calculator.py
    • Arguments are parsed as numbers (float for flexibility)
    • Output formatting: prints integer results as integers (e.g., 5) and floats as decimals
    • Basic error handling:
      • Unknown operation -> prints error message
      • Division by zero -> prints error message and exits with code 1
      • Invalid number input -> prints error message and exits with code 2

Usage examples

  • python calculator.py add 2 3
    • Output: 5
  • python calculator.py subtract 5 2
    • Output: 3
  • python calculator.py multiply 2.5 4
    • Output: 10
  • python calculator.py divide 10 2
    • Output: 5
  • python calculator.py divide 5 0
    • Output: division by zero
  • python calculator.py unknown 1 2
    • Output: Unknown operation: unknown

Notes

  • The script is robust to integer and floating inputs and prints clean output (integers without trailing .0).
  • If you want to extend with more operations (e.g., power, modulo), I can add them with similar CLI ergonomics.

If you’d like, I can run a PR-ready commit or adjust for any additional behaviors you prefer.

Closes #685

New%20session%20-%202026-03-30T00%3A45%3A22.694Z
opencode session  |  github run

Co-authored-by: dzianisv <dzianisv@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a calculator.py script with basic math operations

0 participants