Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by m.dziardziel
def fun(num,step):
if step==1:
first="I"
second="V"
third="X"
elif step==2:
first="X"
second="L"
third="C"
elif step==3:
first="C"
second="D"
third="M"
else:
first="M"
if num==1:
return first
elif num==2:
return first+first
elif num==3:
return first+first+first
elif num==4:
return first+second
elif num==5:
return second
elif num==6:
return second+first
elif num==7:
return second+first+first
elif num==8:
return second+first+first+first
elif num==9:
return first+third
def checkio(data):
roma=""
for a in range(1,5):
cyf=int(data%10)
data=int(data/10)
if cyf==0:
continue
roma=str(fun(cyf,a))+roma
if data<1:
break
return roma
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. 23, 2016