Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by l.szyman10
roman_digits = ['I','V','X','L','C','D','M']
def checkio(data):
#replace this for solution
roman = ''
for i in range(4,0,-1):
scope = (10**(i-1), (roman_digits[2*i-2:2*i+1]))
if data // scope[0] <= 3:
roman += (data // scope[0] * scope[1][0])
elif data // scope[0] == 4:
roman += scope[1][0] + scope[1][1]
elif data // scope[0] < 9:
roman += scope[1][1] + (data // scope[0] - 5)*scope[1][0]
elif data // scope[0] == 9:
roman += scope[1][0] + scope[1][2]
data = data % scope[0]
return roman
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!')
Feb. 25, 2020