Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
inspired by the best solution from "Roman Numerals" solution in Clear category for Reverse Roman Numerals by TKO_Mak
def reverse_roman(roman_string):
"""
IV XL CD IX XC CM I X C M V L D
4 40 400 9 90 900 1 10 100 1000 5 50 500
"""
number=0
for roman, numb in zip("IV XL CD IX XC CM I X C M V L D".split(),"4 40 400 9 90 900 1 10 100 1000 5 50 500".split()):
number=number+roman_string.count(roman)*int(numb)
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!');
Feb. 19, 2018