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