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 jusha
def reverse_roman(roman_string):
d={'CM':-200,'CD':-200,'XC':-20,'XL':-20,'IX':-2,'IV':-2,}
m={'M':1000,'D':500,'C':100,'L':50,'X':10,'V':5,'I':1}
k=0
for i in range(0,len(roman_string)):
if roman_string[i:i+2] in d.keys():
k+=d[roman_string[i:i+2]]
for j in range(0,len(roman_string)):
k+=m[roman_string[j]]
return k
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!');
March 4, 2020