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