Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by szymonkukla1
def checkio(data):
odp = ''
while(data > 0):
if(data / 1000 >= 1):
odp += 'M'
data -= 1000
else:
if(data % 1000 >= 900):
odp += 'CM'
data -= 900
else:
if(data / 500 >= 1):
odp += 'D'
data -= 500
else:
if(data % 500 >= 400):
odp += 'CD'
data -= 400
else:
if(data / 100 >= 1):
odp += 'C'
data -= 100
else:
if(data % 100 >= 90):
odp += 'XC'
data -= 90
else:
if(data / 50 >= 1):
odp +='L'
data -= 50
else:
if(data % 50 >= 40):
odp +='XL'
data -= 40
else:
if(data / 10 >= 1):
odp +='X'
data -= 10
else:
if(data % 10 >= 9):
odp +='IX'
data -= 9
else:
if(data / 5 >= 1):
odp +='V'
data -= 5
else:
if(data % 5 >= 4):
odp +='IV'
data -= 4
else:
if(data / 1 >= 1):
odp += 'I'
data -= 1
return odp
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'
Oct. 23, 2016