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 eugene100372
def reverse_roman(roman_string):
d={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
l=[d[s] for s in reversed(roman_string)]
res=l[0]
for i in range(1,len(l)):
if l[i]>=l[i-1]:
res=res+l[i]
else:
res=res-l[i]
return res
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!');
April 17, 2018