Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Wojtas1411
def checkio(data):
g=0
f=["I","V","X","X","L","C","C","D","M","M"]
h=""
#data=int(data)
while data>0:
if data%10//5==0:
if (data%10)%5==0:
h+=""
elif data%10%5==4:
h=f[g]+f[g+1]+h
else:
for i in range(data%10):
h=f[g]+h
elif data%10//5==1:
if data%10%5==0:
h=f[g+1]+h
elif data%10%5==4:
h=f[g]+f[g+2]+h
else:
for i in range(data%10-5):
h=f[g]+h
h=f[g+1]+h
data//=10
g+=3
return h
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. 7, 2016