Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
string format solution in Uncategorized category for Roman Numerals by toufalk
def checkio(number):
symbols=(('I', 'V', 'X'), ('X', 'L', 'C'), ('C', 'D', 'M'), ('M'))
units=('', '{0}', '{0}{0}', '{0}{0}{0}', '{0}{1}', '{1}', '{1}{0}', '{1}{0}{0}', '{1}{0}{0}{0}', '{0}{2}')
s=""
n=number
for d in range(4):
k=n%10
s=units[k].format(*symbols[d])+s
n=n//10
return s
if __name__ == '__main__':
assert checkio(6) == 'VI', 'First'
assert checkio(76) == 'LXXVI', 'Second'
assert checkio(499) == 'CDXCIX', 'Third'
assert checkio(3888) == 'MMMDCCCLXXXVIII', 'Fourth'
print('All ok')
Dec. 1, 2012
Comments: