Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Tommi
from collections import OrderedDict
numerals = {1000 : "M", 900 : "CM", 500 : "D", 400 : "CD", 100 : "C", 90 : "XC", 50 : "L", 40 : "XL", 10 : "X", 9 : "IX", 5 : "V", 4 : "IV", 1 : "I"}
numerals = OrderedDict(sorted(numerals.items(), reverse=True))
def toRoman(num):
result = ""
roman_prev = 1000
for roman in numerals:
div = num // roman
if div > 3:
result += numerals[roman] * (div - 3)
result += numerals[roman_prev]
else:
result += numerals[roman] * div
num %= roman
roman_prev = roman
return result
def checkio(data):
#replace this for solution
return toRoman(data)
#These "asserts" using only for self-checking and not necessary for auto-testing
May 16, 2014
Comments: