Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Andreas_Strus
def checkio(data):
c = ""
while (data >= 1000):
c = c + "M"
data = data - 1000
if data >= 900:
c = c + "CM"
data = data - 900
if data >= 500:
c = c + "D"
data = data - 500
if data >= 400:
c = c + "CD"
data = data - 400
while (data >= 100):
c = c + "C"
data = data - 100
if data >= 90:
c = c + "XC"
data = data - 90
if data >= 50:
c = c + "L"
data = data - 50
if data >= 40:
c = c + "XL"
data = data - 40
while (data >= 10):
c = c + "X"
data = data - 10
if data >= 9:
c = c + "IX"
data = data - 9
if data >= 5:
c = c + "V"
data = data - 5
if data >= 4:
c = c + "IV"
data = data - 4
while (data >= 1):
c = c + "I"
data = data - 1
return c
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'
Oct. 18, 2016