Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Red_Ale
def checkio(data):
conv = {1000: 'M', 500: 'D', 100: 'C', 50: 'L', 10: 'X', 5: 'V', 1: 'I'}
solut = []
for i in conv:
solut.append((conv[i], divmod(data, i)))
data -= data // i * i
result = ""
for i in range(7):
result += solut[i][0] * solut[i][1][0]
result = result.replace('DCCCC', 'CM')
result = result.replace('CCCC', 'CD')
result = result.replace('LXXXX', 'XC')
result = result.replace('XXXX', 'XL')
result = result.replace('VIIII', 'IX')
result = result.replace('IIII', 'IV')
return result
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(6) == 'VI', '6'
assert checkio(76) == 'LXXVI', '76'
assert checkio(499) == 'CDXCIX', '499'
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
print('Done! Go Check!')
July 7, 2022
Comments: