Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
definitely a bad program. solution in Clear category for Roman Numerals by marcel.sliwinski
def checkio(data):
ans=''
while (data//1000 !=0):
ans=ans+'M'
data=data-1000
if (data//100==9):
ans=ans+'CM'
data=data-900
elif (data//100==4):
ans=ans+'CD'
data=data-400
while (data//500 !=0):
ans=ans+'D'
data=data-500
while (data//100 !=0):
ans=ans+'C'
data=data-100
if (data//10==9):
ans=ans+'XC'
data=data-90
elif (data//10==4):
ans=ans+'XL'
data=data-40
while (data//50 !=0):
ans=ans+'L'
data=data-50
while (data//10 !=0):
ans=ans+'X'
data=data-10
if (data==9):
ans=ans+'IX'
data=data-9
elif (data==4):
ans=ans+'IV'
data=data-4
if (data//5 !=0):
ans=ans+'V'
data=data-5
for i in range(data):
ans=ans+'I'
print(ans)
return ans
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'
Feb. 23, 2017