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