Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by karolk10
def checkio(data):
sol = ""
temp = ""
if data % 10 <= 3:
for i in range(data % 10):
sol = "I" + sol
elif data % 10 == 4:
sol = "IV" + sol
elif data % 10 <= 8:
temp = "V"
for i in range(data % 10 -5):
temp = temp + "I"
sol = temp + sol
temp = ""
else:
sol = "IX" + sol
if data >= 10:
if (data // 10) % 10 <= 3:
for i in range((data // 10) % 10):
sol = "X" + sol
elif (data // 10) % 10 == 4:
sol = "XL" + sol
elif (data // 10) % 10 <= 8:
temp = "L"
for i in range((data // 10) % 10 -5):
temp = temp + "X"
sol = temp + sol
temp = ""
else:
sol = "XC" + sol
if data >= 100:
if (data // 100) % 10 <= 3:
for i in range((data // 100) % 10):
sol = "C" + sol
elif (data // 100) % 10 == 4:
sol = "CD" + sol
elif (data // 100) % 10 <= 8:
temp = "D"
for i in range((data // 100) % 10 -5):
temp = temp + "C"
sol = temp + sol
temp = ""
else:
sol = "CM" + sol
if (data // 1000) > 0:
for i in range((data // 1000) % 10):
sol = "M" + sol
return sol
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'
Nov. 15, 2016