Two roman numbers are passed as strings.
You need to compare them and return -1, if the first is greater, 0 if they are equal and 1 otherwise
def from_roman(num):
roman_numerals = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
result = 0
for i, c in enumerate(num):
if (i+1) == len(num) or roman_numerals[c] >= roman_numerals[num[i+1]]:
result += roman_numerals[c]
else:
result -= roman_numerals[c]
return result
def compare_roman(a, b):
a = from_roman(a)
b = from_roman(b)
if a < b:
return -1
elif a == b:
return 0
else:
return 1
test.assert_equals(compare_roman('XX', 'XL'), -1)
test.assert_equals(compare_roman('MM', 'MM'), 0)
test.assert_equals(compare_roman('X', 'V'), 1)