Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Roman Numerals solution in Uncategorized category for Roman Numerals by Elena_Korljukova
num = {1: 'I', 5: 'V', 10: 'X', 50: 'L', 100: 'C', 500: 'D', 1000: 'M'}
def checkio(data):
s = ''
n = len(str(data)) - 1
while n >= 0:
x = int(str(data)[- n - 1])
p = 10**n
s += x * num[p] if x < 4 else num[p] + num[p * 5] if x == 4 else num[p * 5] + x % 5 * num[p] if x < 9 else num[p] + num[p * 10]
n -= 1
return s
if __name__ == '__main__':
print(checkio(499))
#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!')
June 21, 2020