Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
better solution in Clear category for Roman Numerals by grazik
rzymskie = ['M', 'D', 'C', 'L', 'X', 'V', 'I']
def adding(q,i):
z = ''
while q > 0:
if q == 9:
z += rzymskie[i+1]+rzymskie[i-1]
q -=9
elif q >= 5:
z += rzymskie[i]
q -=5
elif q >= 4:
z += rzymskie[i+1]+rzymskie[i]
q -= 4
else:
z += rzymskie[i+1]
q-= 1
return z
def checkio(data):
z = ''
z += rzymskie[0]*(data//1000)
data -= (data//1000)*1000
for i in range(3):
q = data
q = q//10**(2-i)
data -= q*10**(2-i)
z += adding(q,2*i+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