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