Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Reverse Roman Numerals by wo.tomasz
def reverse_roman(roman_string):
roman_string = roman_string.replace('CM', '900 ').replace('CD', '400 ').replace('XC', '90 ').replace('XL', '40 ').replace('IX', '9 ').replace('IV', '4 ')
roman_string = roman_string.replace('M', '1000 ').replace('D', '500 ').replace('C', '100 ').replace('L', '50 ').replace('X', '10 ').replace('V', '5 ').replace('I', '1 ')
num_list = [int(i) for i in roman_string.strip().split(' ')]
return sum(num_list)
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!');
Dec. 13, 2020
Comments: