Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple and readable solution in Clear category for Roman Numerals by malion
def checkio(data):
m = ["", "M", "MM", "MMM"]
c = ["", "C", "CC", "CCC", "CD", "D",
"DC", "DCC", "DCCC", "CM"]
x = ["", "X", "XX", "XXX", "XL", "L",
"LX", "LXX", "LXXX", "XC"]
i = ["", "I", "II", "III", "IV", "V",
"VI", "VII", "VIII", "IX"]
ths = m[data // 1000]
hs = c[(data % 1000) // 100]
ts = x[(data % 100) // 10]
os = i[data % 10]
return ths + hs + ts + os
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!')
March 3, 2023
Comments: