Skip to content

Added calculator.py CLI tool#686

Open
opencode-agent[bot] wants to merge 1 commit intomainfrom
opencode/issue685-20260330004524
Open

Added calculator.py CLI tool#686
opencode-agent[bot] wants to merge 1 commit intomainfrom
opencode/issue685-20260330004524

Conversation

@opencode-agent
Copy link
Copy Markdown

Implemented the calculator tool.

What I added

  • File: calculator.py at repository root
  • Features:
    • Command-line interface with subcommands: add, subtract, multiply, divide
    • Arguments: a and b (parsed as floats)
    • Outputs:
      • Prints integer results as integers (e.g., 5 instead of 5.0) when the result is a whole number
      • Prints floats for non-integer results (e.g., 2.5)
    • Basic error handling for division by zero

How it works

  • Usage examples:
    • python calculator.py add 2 3 -> prints 5
    • python calculator.py subtract 10 4 -> prints 6
    • python calculator.py multiply 3 4 -> prints 12
    • python calculator.py divide 5 2 -> prints 2.5

Minimal behavior notes

  • Division by zero raises a ZeroDivisionError with a clear message.

Patch summary

  • Added calculator.py with:
    • add, subtract, multiply, divide functions
    • CLI implemented via argparse with subparsers
    • _format_result to emit clean integer output when appropriate

If you’d like, I can add basic unit tests for these operations or extend the CLI to support integer-only inputs or more advanced features.

Closes #685

New%20session%20-%202026-03-30T00%3A45%3A23.699Z
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