Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
My Solution! solution in Uncategorized category for Reverse Roman Numerals by IvoVanLeeuwen
def reverse_roman(roman_string):
dict = {'I': 1, 'V': 5, 'X': 10,'L': 50,'C': 100,'D': 500,'M': 1000}
total = 0
prevchar = "M"
for char in roman_string:
total += dict[char]
if dict[char] > dict[prevchar]:
total -= 2*dict[prevchar]
prevchar = char
print (total)
return total
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!');
Sept. 1, 2017
Comments: