Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Kamil0320
def M(m):
return m*"M"
def KK(a1,a2,ch1,ch2,ch3):
if a1==1 and a2==4:
return ch1+ch3
elif a1==0 and a2==4:
return ch1+ch2
else:
return a1*ch2+a2*ch1
def listing(data):
list=[]
for i in [1000,500,100,50,10,5,1]:
list.append(data//i)
data=data%i
return list
def checkio(data):
list=listing(data)
num=M(list[0])+KK(list[1],list[2],"C","D","M")+KK(list[3],list[4],"X","L","C")+KK(list[5],list[6],"I","V","X")
return num
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