Skip to main content

Docutils -- Python Documentation Utilities

Project description

A library for manipulating well-formed Roman numerals.

Integers between 1 and 3,999 (inclusive) are supported. Numbers beyond this range will return an OutOfRangeError.

The classical system of roman numerals requires that the same character may not appear more than thrice consecutively, meaning that ‘MMMCMXCIX’ (3,999) is the largest well-formed Roman numeral. The smallest is ‘I’ (1), as there is no symbol for zero in Roman numerals.

Both upper- and lower-case formatting of roman numerals are supported, and likewise for parsing strings, although the entire string must be of the same case. Numerals that do not adhere to the classical form are rejected with an InvalidRomanNumeralError.

Example usage

Creating a roman numeral

from roman_numerals import RomanNumeral

num = RomanNumeral(16)
assert str(num) == 'XVI'

num = RomanNumeral.from_string("XVI")
assert int(num) == 16

Convert a roman numeral to a string

from roman_numerals import RomanNumeral

num = RomanNumeral(16)
assert str(num) == 'XVI'
assert num.to_uppercase() == 'XVI'
assert num.to_lowercase() == 'xvi'
assert repr(num) == 'RomanNumeral(16)'

Extract the decimal value of a roman numeral

from roman_numerals import RomanNumeral

num = RomanNumeral(42)
assert int(num) == 42

Invalid input

from roman_numerals import RomanNumeral, InvalidRomanNumeralError

num = RomanNumeral.from_string("Spam!")  # raises InvalidRomanNumeralError
num = RomanNumeral.from_string("CLL")  # raises InvalidRomanNumeralError
num = RomanNumeral(0)  # raises OutOfRangeError
num = RomanNumeral(4_000)  # raises OutOfRangeError

Licence

This project is licenced under the terms of either the Zero-Clause BSD licence or the CC0 1.0 Universal licence. See LICENCE.rst for the full text of both licences.

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

roman_numerals_py-2.0.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

roman_numerals_py-2.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file roman_numerals_py-2.0.0.tar.gz.

File metadata

  • Download URL: roman_numerals_py-2.0.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for roman_numerals_py-2.0.0.tar.gz
Algorithm Hash digest
SHA256 2fcf8219331c0ec5a29d5c4c8553f3edd251696496db117f7181d15687e66f5e
MD5 d8ee96649c3a8fcc38d1f03c24b533fd
BLAKE2b-256 bb6faa38863bef8d46f4f606cb6c218cae86b11de930d259cd9e4a352589b030

See more details on using hashes here.

Provenance

The following attestation bundles were made for roman_numerals_py-2.0.0.tar.gz:

Publisher: create-release.yml on AA-Turner/roman-numerals

Attestations:

File details

Details for the file roman_numerals_py-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for roman_numerals_py-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36b6d2b2b4e2d3ba53356503dbb525dafa1334f6c31baef6580a5a1194c0c6f9
MD5 85f462cf7d5aeff8894d915d9f152a41
BLAKE2b-256 d9d5ca29876e2f5640afc2cc2ff653715244fcc4fea1f189d972b5410144c04d

See more details on using hashes here.

Provenance

The following attestation bundles were made for roman_numerals_py-2.0.0-py3-none-any.whl:

Publisher: create-release.yml on AA-Turner/roman-numerals

Attestations:

Supported by

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