Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Roman Numerals by axaroth
# migrated from python 2.7
table = [
('M', 1000),
('CM', 900),
('D', 500),
('CD', 400),
('C', 100),
('XC', 90),
('L', 50),
('XL', 40),
('X',10),
('IX',9),
('V',5),
('IV',4),
('I',1),
]
def checkio(number):
'return roman numeral using the specified integer value from range 1...3999'
numerals = []
rest = number
for symbol, value in table:
numerals.append(symbol*(rest//value))
rest = rest%value
return ''.join(numerals)
if __name__ == '__main__':
assert checkio(6) == 'VI', 'First'
assert checkio(76) == 'LXXVI', 'Second'
print('All ok')
April 14, 2011
Comments: