Skip to main content

A Python package for converting Roman numerals and written numbers to integers

Project description

Numeric Converter

A Python package for converting Roman numerals and written numbers to integers.

Features

  • Roman Numeral Conversion: Convert Roman numerals (I, V, X, L, C, D, M) to integers
  • Written Number Conversion: Convert written numbers ("one", "two", etc.) to integers
  • Error Handling: Proper validation and error messages for invalid inputs
  • Comprehensive Coverage: Supports numbers from zero to twenty for written numbers

Installation

pip install numeric-converter

Quick Start

from numeric_converter import roman_to_int, written_number_to_int

# Convert Roman numerals
print(roman_to_int("IV"))        # Output: 4
print(roman_to_int("IX"))        # Output: 9
print(roman_to_int("MCMXC"))     # Output: 1990

# Convert written numbers
print(written_number_to_int("five"))     # Output: 5
print(written_number_to_int("twenty"))   # Output: 20
print(written_number_to_int("invalid"))  # Output: -1

API Reference

roman_to_int(s)

Convert a Roman numeral string to an integer.

Parameters:

  • s (str): Roman numeral string (e.g., 'IV', 'IX', 'MCMXC')

Returns:

  • int: The integer value of the Roman numeral

Raises:

  • ValueError: If the input contains invalid Roman numeral characters

Examples:

>>> roman_to_int('IV')
4
>>> roman_to_int('LVIII')
58
>>> roman_to_int('MCMXC')
1990

written_number_to_int(s)

Convert a written number word to an integer.

Parameters:

  • s (str): Written number word (e.g., 'one', 'two', 'ten')

Returns:

  • int: The integer value of the written number, or -1 if not found

Supported Numbers:

  • zero through twenty (0-20)
  • Case-insensitive input

Examples:

>>> written_number_to_int('five')
5
>>> written_number_to_int('FIFTEEN')
15
>>> written_number_to_int('invalid')
-1

Roman Numeral Rules

The package follows standard Roman numeral conversion rules:

  • Basic Symbols: I=1, V=5, X=10, L=50, C=100, D=500, M=1000
  • Additive Principle: When a smaller numeral appears after a larger one, add them (VI = 6)
  • Subtractive Principle: When a smaller numeral appears before a larger one, subtract it (IV = 4)

Development

Setting up for Development

# Clone the repository
git clone https://github.com/yourusername/numeric-converter.git
cd numeric-converter

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

# Install in development mode
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black src/
flake8 src/

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

v0.1.0

  • Initial release
  • Roman numeral to integer conversion
  • Written number to integer conversion
  • Comprehensive error handling
  • Full test coverage

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numeric_converter-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numeric_converter-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file numeric_converter-0.1.0.tar.gz.

File metadata

  • Download URL: numeric_converter-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for numeric_converter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4732c2ccdeab4c8926dcb5bd51e19af331a40bbd31bfdc31884aecad5471d5c0
MD5 0586db33287c07f1ef40bc3904814075
BLAKE2b-256 ff0a34fe3978cd0b26ced783dd6575a84db687022267fd3a1cdd43bf3195dfc3

See more details on using hashes here.

File details

Details for the file numeric_converter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for numeric_converter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 554010efe2ea86596eff8271dd310dd097cd5bcf7b31c18fec1518a96116d7ae
MD5 b9bcd05cee3c7c3f061b791b2cd56471
BLAKE2b-256 39d25c1655f9b697668905ce79fdbf3d3c48e40fbd00f532d803a127e9094fb5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page