Roman Numeral Converter

5.2 · active · verified Sat Apr 11

The `roman` library is a small, active Python utility that facilitates the conversion of Arabic (decimal) integers to Roman numerals and vice versa. Currently at version 5.2, it supports Python 3.10 and newer, with a history of regular updates often tied to Python version compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to convert between integers and Roman numerals using `roman.toRoman()` and `roman.fromRoman()`. It also shows how the library handles the special case for zero ('N') and catches errors for invalid Roman numeral input.

import roman

# Convert integer to Roman numeral
numeral = roman.toRoman(1994)
print(f"1994 in Roman numerals: {numeral}")

# Convert Roman numeral to integer
integer = roman.fromRoman('MCMXCIV')
print(f"MCMXCIV as an integer: {integer}")

# Example with zero (N)
zero_numeral = roman.toRoman(0)
print(f"0 in Roman numerals: {zero_numeral}")

# Handling invalid input
try:
    invalid_int = roman.fromRoman('ABC')
    print(invalid_int)
except roman.InvalidRomanNumeralError as e:
    print(f"Error converting 'ABC': {e}")

view raw JSON →