Skip to content
Michael Lizzio

Roman Numeral Converter

An early two-way Roman numeral converter with its own validity check

  • Python
  • NumPy
  • Command-line interface

Complete

Ancient Roman inscription on a stone slab with the title Roman Numeral Converter
Adapted from a photograph by Sonse, licensed CC BY 2.0.
What it is
A Python program that converts Roman numerals to regular numbers and back, and checks whether a Roman numeral is written correctly.
Why I made it
It was one of the first things I wrote on my Raspberry Pi, before I even knew about while loops.
What I did
I came up with my own way to check the input: turn it into a number, turn that back into a Roman numeral, and see if it matches what you typed.
How it turned out
It works, and it's a fun snapshot of how I solved problems before I knew the normal tools for them. You can try it right on this page.

The details

Try the converter

Convert in either direction, then open the trace to see exactly how the answer was built.

Conversion direction

Use I, V, X, L, C, D, and M.

Try an example:

Your result will appear here.

A strange but useful validator

The program reads your Roman numeral, turns the answer back into a properly written Roman numeral, and compares the two. If they don't match, it rejects things like IIII and suggests IV instead.

How the two directions work

Reading a Roman numeral goes left to right. A symbol gets added when it's at least as big as the one after it, and subtracted when a bigger one comes next. That's why VI is 5 + 1, but IV is -1 + 5.

Writing one goes the other way. The converter keeps taking the biggest symbol or pair, like CM or IV, that fits into the number, adds it, and keeps going with what's left. You can try it in the converter above.