Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Roman Numerals by silg2
def checkio(number):
'return roman numeral using the specified integer value from range 1...3999'
bases=[1000,900,500,400,100,90,50,40,10,9,5,4,1]
letters=['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV','I']
string=''
for base, letter in list(zip(bases,letters)):
root=number//base
string+=''.join(letter for i in range(0,root))
number-=root*base
return string
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')
Nov. 10, 2012
Comments: