Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Roman Numerals by nickie
def checkio(number):
answer = []
if number >= 1000:
answer.append('M'*(number//1000))
number %= 1000
if number >= 100:
answer.append(['C','CC','CCC','CD','D','DC','DCC','DCCC','CM'][number//100-1])
number %= 100
if number >= 10:
answer.append(['X','XX','XXX','XL','L','LX','LXX','LXXX','XC'][number//10-1])
number %= 10
if number >= 1:
answer.append(['I','II','III','IV','V','VI','VII','VIII','IX'][number-1])
return "".join(answer)
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(6) == 'VI', '6'
assert checkio(76) == 'LXXVI', '76'
assert checkio(499) == 'CDXCIX', '499'
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
Oct. 12, 2013