Skip to content

terrymclaughlin/copilot-python-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Calculator

A simple command-line calculator written in Python. Supports four arithmetic operations with input validation, error handling, and a full pytest test suite.

Features

  • Addition, subtraction, multiplication, and division
  • Input validation — rejects non-numeric arguments with a clear error
  • Division-by-zero protection
  • Clean CLI powered by argparse
  • Comprehensive test coverage with pytest

Requirements

  • Python 3.x

Installation

# Clone the repository
git clone https://github.com/terrymclaughlin/copilot-python-calculator.git
cd copilot-python-calculator

# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate   # On Windows: .venv\Scripts\activate

# Install test dependencies
pip install pytest

Usage

python calculator.py <operation> <a> <b>
Operation Command Result
Addition python calculator.py add 5 3 8.0
Subtraction python calculator.py subtract 10 4 6.0
Multiplication python calculator.py multiply 3 4 12.0
Division python calculator.py divide 10 2 5.0

Error cases

# Division by zero
python calculator.py divide 5 0
# Error: Cannot divide by zero

# Invalid input
python calculator.py add foo 3
# error: argument a: invalid float value: 'foo'

Running Tests

# Run all tests
pytest test_calculator.py

# Run with verbose output
pytest -v test_calculator.py

Project Structure

copilot-python-calculator/
├── calculator.py        # Core operations and CLI entry point
├── test_calculator.py   # Pytest test suite
└── .venv/               # Python virtual environment (not committed)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages