Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dict and replace solution in Creative category for Reverse Roman Numerals by telosMancera
def reverse_roman (roman_string) :
t = (('CM', 900),
('M', 1000),
('CD', 400),
('D', 500),
('XC', 90),
('C', 100),
('XL', 40),
('L', 50),
('IX', 9),
('X', 10),
('IV', 4),
('V', 5),
('I', 1))
number = 0
for roman, integer in t :
number += roman_string.count(roman) * integer
roman_string = roman_string.replace(roman, '')
return number
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!');
Oct. 25, 2017