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