Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by lancelote
def convert_num(num, unit, five_unit, next_unit):
"""
Convert a single digit to roman according to an order
"""
result = ''
if num < 4:
result += unit*num
elif num == 4:
result += unit + five_unit
elif num < 9:
result += five_unit + unit*(num - 5)
else:
result += unit + next_unit
return result
def checkio(num):
result = ''
for order in [('I', 'V', 'X'),
('X', 'L', 'C'),
('C', 'D', 'M'),
('M', '_', '_')]:
num, current = divmod(num, 10) # Next digit
result = convert_num(current, *order) + result
return result
May 17, 2015
Comments: