Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using dict solution in Clear category for Roman Numerals by MrPod
def checkio(data):
romans = dict(zip([1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000],
['I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M']))
i = len(romans) - 1
res = ''
while data > 0:
a = list(romans.keys())[i]
if data >= a:
res += romans[a]
data -= a
else:
i -= 1
return res
Jan. 27, 2018