Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Working but bad solution in Clear category for Roman Numerals by grazik
rzymskie = ['M', 'D', 'C', 'L', 'X', 'V', 'I']
def checkio(data):
z = ''
z += 'M'*(data//1000)
data -= (data//1000)*1000
q = data
q = q//100
data -= q*100
while q > 0:
if q == 9:
z +='CM'
q -=9
elif q >= 5:
z += 'D'
q -=5
elif q >= 4:
z += 'CD'
q -= 4
else:
z += 'C'
q-= 1
q = data
q = q//10
data -= q*10
while q > 0:
if q == 9:
z +='XC'
q -=9
elif q >= 5:
z += 'L'
q -=5
elif q >= 4:
z += 'XL'
q -= 4
else:
z += 'X'
q-= 1
q = data
while q > 0:
if q == 9:
z +='IX'
q -=9
elif q >= 5:
z += 'V'
q -=5
elif q >= 4:
z += 'IV'
q -= 4
else:
z += 'I'
q-= 1
return z
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. 19, 2016