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