Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by McRawicz
def checkio(data):
x=""
#M:
m=data//1000
while m>0:
x+="M"
m-=1
data-=1000
if data>=900:
x+="CM"
data-=900
#D:
d=data//500
while d>0:
x+="D"
d-=1
data-=500
if data>=400:
x+="CD"
data-=400
#C:
c=data//100
while c>0:
x+="C"
c-=1
data-=100
if data>=90:
x+="XC"
data-=90
#L:
l=data//50
while l>0:
x+="L"
l-=1
data-=50
if data>=40:
x+="XL"
data-=40
#X:
xx=data//10
while xx>0:
x+="X"
xx-=1
data-=10
if data==9:
x+="IX"
return x
#V
v=data//5
while v>0:
x+="V"
v-=1
data-=5
if data==4:
x+="IV"
return x
#I:
while data>0:
x+="I"
data-=1
return x
Oct. 21, 2016