24Roman Numerals to Integer
Mediumdictionariesstrings
Write roman_to_int(s) that converts a Roman numeral to an integer.
The symbols are I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Normally they add up, but a smaller symbol before a larger one is subtracted: IV is 4 and XC is 90.
Examples
Example 1
>>> roman_to_int('III') 3
Example 2
>>> roman_to_int('MCMXCIV') 1994
Run examples checks the 2 examples above. Submit runs all 7 tests, including hidden edge cases, and marks the challenge solved.