Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by ryosms
def checkio(data):
if data >= 1000:
return "M" + checkio(data - 1000)
if data >= 900:
return "CM" + checkio(data - 900)
if data >= 500:
return "D" + checkio(data - 500)
if data >= 400:
return "CD" + checkio(data - 400)
if data >= 100:
return "C" + checkio(data - 100)
if data >= 90:
return "XC" + checkio(data - 90)
if data >= 50:
return "L" + checkio(data - 50)
if data >= 40:
return "XL" + checkio(data - 40)
if data >= 10:
return "X" + checkio(data - 10)
if data >= 9:
return "IX" + checkio(data - 9)
if data >= 5:
return "V" + checkio(data - 5)
if data >= 4:
return "IV" + checkio(data - 4)
if data >= 1:
return "I" + checkio(data - 1)
#replace this for solution
return ""
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(6) == 'VI', '6'
assert checkio(76) == 'LXXVI', '76'
assert checkio(499) == 'CDXCIX', '499'
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
Feb. 26, 2014
Comments: