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 Venigret
from collections import OrderedDict
def reverse_roman(roman_string):
numdict = OrderedDict()
for l, n in ("I",1),("V",5),("X",10),("L",50),("C",100),("D",500),("M",1000):
numdict.update({l:n})
answer = 0
buff = 0
for num in roman_string[::-1]:
if buff <= numdict[num]:
buff = numdict[num]
answer += numdict[num]
else:
answer -= numdict[num]
#replace this for solution
return answer
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!');
Jan. 25, 2022
Comments: