Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Reverse Roman Numerals by MKaa01
def reverse_roman(roman_string):
rom=0
ROMANS = (('CM', 900),
('CD', 400),
('XC', 90),
('XL', 40),
('IX', 9),
('IV', 4),
('M', 1000),
('D', 500),
('C', 100),
('L', 50),
('X', 10),
('V', 5),
('I', 1))
for roman in ROMANS:
while True:
if roman[0] in roman_string:
rom += roman[1]
roman_string=roman_string.replace(roman[0],"", 1)
if not roman[0] in roman_string:
break;
#replace this for solution
return rom
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert reverse_roman('VI') == 6, '6'
assert reverse_roman('LXXVI') == 76, '76'
assert reverse_roman('CDXCIX') == 499, '499'
assert reverse_roman('MMMDCCCLXXXVIII') == 3888, '3888'
print('Great! It is time to Check your code!');
Jan. 21, 2018