Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Razzerrer
def checkio(data):
i=0
Roman_number=""
if int(data/1000)!=0:
while i < int(data/1000):
Roman_number += "M"
i+=1
i=0
data-=(int(data/1000)*1000)
if int(data/900)!=0:
Roman_number += "CM"
data-=900
if int(data/500)!=0:
Roman_number += "D"
data-=500
if int(data/400)!=0:
Roman_number += "CD"
data-=400
if int(data/100)!=0:
while i < int(data/100):
Roman_number += "C"
i+=1
i=0
data-=(int(data/100)*100)
if int(data/90)!=0:
Roman_number += "XC"
data-=90
if int(data/50)!=0:
Roman_number += "L"
data-=50
if int(data/40)!=0:
Roman_number += "XL"
data-=40
if int(data/10)!=0:
while i < int(data/10):
Roman_number += "X"
i+=1
i=0
data-=(int(data/10)*10)
if int(data/9)!=0:
Roman_number += "IX"
data-=9
if int(data/5)!=0:
Roman_number += "V"
data-=5
if int(data/4)!=0:
Roman_number += "IV"
data-=4
if int(data/1)!=0:
while i < int(data/1):
Roman_number += "I"
i+=1
return Roman_number
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