Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by voxes96
def conv(x, i):
let = ["I", "V", "X", "L", "C", "D", "M"]
if(x==1):
return let[2*i]
elif(x==2):
return let[2*i]+let[2*i]
elif(x==3):
return let[2*i]+let[2*i]+let[2*i]
elif(x==4):
return let[2*i]+let[1+2*i]
elif(x==5):
return let[1+2*i]
elif(x==6):
return let[1+2*i]+let[2*i]
elif(x==7):
return let[1+2*i]+let[2*i]+let[2*i]
elif(x==8):
return let[1+2*i]+let[2*i]+let[2*i]+let[2*i]
elif(x==9):
return let[2*i]+let[2+2*i]
else:
return ""
def checkio(data):
letter = ["I", "V", "X", "L", "C", "D", "M"]
i = 0
tmp = 0
rome = ""
while(data>0):
tmp = data % 10
data = data // 10
rome = conv(tmp,i) + rome
i = i + 1
return rome
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