Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Roman Numerals by Julita_Pogorzelska
def checkio(data):
'''"I"=int(1)
"V"=int(5)
"X"=int(10)
"L"=int(50)
"C"=int(100)
"D"=int(500)
"M"=int(1000)'''
romanno=""
while data>0:
if data>=1000:
romanno+="M"
data-=1000
elif data>=500:
romanno+="D"
data-=500
elif data>=100:
romanno+="C"
data-=100
elif data>=50:
romanno+="L"
data-=50
elif data>=10:
romanno+="X"
data-=10
elif data>=5:
romanno+="V"
data-=5
elif data>=1:
romanno+="I"
data-=1
romanno=romanno.replace("DCCCC", "CM")
romanno=romanno.replace("CCCC", "CD")
romanno=romanno.replace("LXXXX", "XC")
romanno=romanno.replace("XXXX", "XL")
romanno=romanno.replace("VIIII", "IX")
romanno=romanno.replace("IIII", "IV")
return romanno
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. 1, 2018