Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by welv
def checkio(data):
num=""
r=0
ile=0
w=[]
temp=data
list1=[1000,500,100,50,10,5,1]
list2=['M','D','C','L','X','V','I',""]
list3=[2,1,2,1,2,1,1]
list4=[900,400,90,40,9,4,-10]
for i in range(len(list1)):
ile=temp//list1[i]
r=temp%list1[i]
print(list1[i],list4[i])
if temp>=list1[i]:
for j in range(ile):
num=num+list2[i]
temp=temp-list1[i]
print(num,ile)
if temp>=list4[i] and temp!=0:
num=num+list2[i+list3[i]]+list2[i]
print(temp,i)
temp=temp-list4[i]
else:
if temp>=list4[i] and temp!=0:
num=num+list2[i+list3[i]]+list2[i]
print(temp,i)
temp=temp-list4[i]
print('num=',num)
return num
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'
Jan. 20, 2017