Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Bartek.Knobel
def checkio(data):
x = ""
tys = data // 1000
for i in range(tys):
x = x + "M"
set_zos = data % 1000
set = set_zos // 100
if set < 4:
for i in range(set):
x = x + "C"
elif set == 4:
x = x + "CD"
elif set == 9:
x = x + "CM"
else:
se = set - 5
x = x + "D"
for i in range(se):
x = x + "C"
dzie_zos = set_zos % 100
dzie = dzie_zos // 10
if dzie < 4:
for i in range(dzie):
x = x + "X"
elif dzie == 4:
x = x + "XL"
elif dzie == 9:
x = x + "XC"
else:
dz = dzie - 5
x = x + "L"
for i in range(dz):
x = x + "X"
jed = dzie_zos % 10
if jed < 4:
for i in range(jed):
x = x + "I"
elif jed == 4:
x = x + "IV"
elif jed == 9:
x = x + "IX"
else:
je = jed - 5
x = x + "V"
for i in range(je):
x = x + "I"
return x
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
Oct. 21, 2016