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