This is a simple Python script that takes a Roman numeral as input and outputs its decimal equivalent.
The script follows the traditional rules of Roman numerals to convert the input to a decimal number (1 to 3,999):
- When certain numerals are repeated, the number represented by them is their sum. For example, II = 1 + 1 = 2.
- No Roman numerals can come together more than 3 times.
- The letters V, L, and D are not repeated.
- Only I, X, and C can be used as subtractive numerals, and must not be repeated (IIX not allowed).
- When a Roman numeral is placed after another Roman numeral of greater value, the result is the sum of the numerals.
- When a Roman numeral is placed before another Roman numeral of greater value, the result is the difference between the numerals.
- When a Roman numeral of a smaller value is placed between two numerals of greater value, it is subtracted from the numeral on its right.
- Roman numerals strictly represent units (I), tens (X), hundreds (C), and thousands (M) as separate items, following the arrangement on an abacus.
- Roman numerals do not follow any place value system.
- There is no Roman numeral for zero (0).
This script requires Python 3.6 or later.
Run the script from the command line:
python3 roman_numeral.py
Enter a Roman numeral when prompted. The script accepts upper- and lowercase Roman numerals.
The script outputs the decimal equivalent of the input Roman numeral.
You can exit the program by either submitting a valid Roman numeral or, if in a Unix-based environment, sending EOF (End of File, such as ^d) on a blank line.
For any issues with input validation, refer to the rules above. The script will raise a ValueError with a detailed message for invalid inputs.
This project is licensed under the GPL-3.0 license. The GPL-3.0 license allows for free distribution, modification, and use of the software, but requires the same licensing when the project is distributed further.