Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Drugi Roman solution in Clear category for Roman Numerals by Adrian_W
def paste(quantity, character):
output=""
for x in range(0, quantity):
output+=character
return output
def checkio(data):
output=""
stageList=(1000,500,100,50,10,5,1)
charList =('M','D','C','L','X','V','I')
for i in range (0,len(stageList)):
for j in range (0, len(stageList)):
if j>1 and data >= stageList[j-2]-stageList[j] and stageList[j-2]>data and j%2==0:
data-=(stageList[j-2]-stageList[j])
output+=charList[j]
output+=charList[j-2]
print(output)
break
for j in range (0, len(stageList)):
if j>0 and data >= stageList[j-1]-stageList[j] and stageList[j-1]>data and j%2==0:
data-= stageList[j-1]-stageList[j]
output+=charList[j]
output+=charList[j-1]
print(output)
break
else :
output+=paste(data//stageList[i],charList[i])
data-= (data//stageList[i])*stageList[i]
print (data)
return output
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
Comments: