Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by spark856
symbol = ["IV","XL","CD","M"]
def checkio(data):
ld = len(str(data))-1
ans = ""
for i in map(int,str(data)):
if i==0:pass
elif i<4:ans += symbol[ld][0]*i
elif i==4:ans += symbol[ld]
elif i<9:ans += symbol[ld][1]+symbol[ld][0]*(i-5)
else:ans += symbol[ld][0] + symbol[ld+1][0]
ld -= 1
return ans
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'
print('Done! Go Check!')
April 28, 2020