Roman Numeral Conversion in Every LanguagePublished on 01 November 2018 (Updated: 02 May 2020)
Roman numerals are the numbers that were used in ancient Rome, which employed combinations of letters from the Latin alphabet (I, V, X, L, C, D and M).
The following table shows the letter to decimal mapping:
Stringing together these digits yields a value that is the sum of their respective mappings. However, there is a catch. Roman numerals must appears in order of greatest to least. If a smaller value appears before a larger one, the smaller value is subtracted from the total.
As a result, a string like
XV would evaluate to 15 while
evaluate to 14.
Of course, there are other limitations, but we’ll ignore those for simplicity.
Create a file called Roman Numeral Conversion using whatever naming convention is appropriate for the choice language.
Using the table above, write a sample program which accepts a Roman numeral on
the command line and outputs its decimal value on standard output. Be careful
to appropriately handle invalid input such as
XT. More on that in the testing
Please make sure your program is executable. In other words, the solution
should be able to be called in the appropriate environment with a string
of roman numerals (i.e.
The following table contains appropriate examples for testing a Roman Numeral Conversion program:
|No Input||“Usage: please provide a string of roman numerals”|
|Invalid Input||“XT”||“Error: invalid string of roman numerals”|
- Roman Numeral Conversion in Python on 27 October 2019 by Vikram Rayavarapu
- Fill as needed