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