Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Rafal__Kotas
def checkio(data):
A = ['1000','500','100','50','10','5','1']
R = ['M','D','C','L','X','V','I']
x = data
sytry=''
i = 0
while(x>0):
if(int(A[i])<= x):
if((x>=900 and x<1000) or (x<100 and x>=90) or (x == 9)):
sytry = sytry + R[i+1]
sytry = sytry + R[i-1]
x = x - (int(A[i-1])-int(A[i+1]))
else:
if((x<50 and x>=40) or (x<5 and x>=4) or (x<500 and x>=400)):
sytry = sytry + R[i] + R[i-1]
x = x-(int(A[i-1])-int(A[i]))
else:
sytry=sytry+R[i]
x = x - int(A[i])
else:
i = i + 1
return (sytry)
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'
Nov. 1, 2016