Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by stanwys
def zam(n,l):
x=""
if(l==1):
if(n>=5):
if(n==9):
x="IX"
else:
x="V"
for i in range(n-5):
x=x+"I"
else:
if(n==4):
x="IV"
else:
x=""
for i in range(n):
x=x+"I"
elif l==2:
x=""
if n>=5:
if(n==9):
x="XC"
else:
x="L"
if n==6:
x=x+"X"
elif n==7:
x=x+"XX"
elif n==8:
x=x+"XXX"
else:
if(n==4):
x="XL"
elif n==3:
x="XXX"
elif n==2:
x="XX"
elif n==1:
x="X"
elif(l==3):
x=""
if(n>=5):
if(n==9):
x="CM"
else:
x="D"
if(n==6):
x=x+"C"
elif n==7:
x=x+"CC"
elif n==8:
x=x+"CCC"
else:
if(n==4):
x="CD"
elif n==3:
x="CCC"
elif n==2:
x="CC"
elif n==1:
x="C"
elif(l==4):
if(n==3):
x="MMM"
elif n==2:
x="MM"
elif n==1:
x="M"
return x
def checkio(d):
w=""
pom=""
l=1
while d!=0:
r=int(d)%10
pom=zam(r,l)
w=pom+w
d=int(d)/10
l=l+1
#replace this for solution
return w
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. 21, 2016