Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by HubertDolny
def checkio(data):
#replace this for solution
n= str(data)
x=len(n)
answer= ""
if n[len(n)-1]=="1":
answer="I"
if n[len(n)-1]=="2":
answer="II"
if n[len(n)-1]=="3":
answer="III"
if n[len(n)-1]=="4":
answer="IV"
if n[len(n)-1]=="5":
answer="V"
if n[len(n)-1]=="6":
answer="VI"
if n[len(n)-1]=="7":
answer="VII"
if n[len(n)-1]=="8":
answer="VIII"
if n[len(n)-1]=="9":
answer="IX"
print (x)
if x>=2:
if n[len(n)-2]=="1":
answer="X" + answer
if n[len(n)-2]=="2":
answer="XX" + answer
if n[len(n)-2]=="3":
answer="XXX"+answer
if n[len(n)-2]=="4":
answer="XL" + answer
if n[len(n)-2]=="5":
answer="L" + answer
if n[len(n)-2]=="6":
answer="LX"+answer
if n[len(n)-2]=="7":
answer="LXX" + answer
if n[len(n)-2]=="8":
answer="LXXX" + answer
if n[len(n)-2]=="9":
answer="XC"+answer
if x>=3:
if n[len(n)-3]=="1":
answer="C" + answer
if n[len(n)-3]=="2":
answer="CC" + answer
if n[len(n)-3]=="3":
answer="CCC"+answer
if n[len(n)-3]=="4":
answer="CD" + answer
if n[len(n)-3]=="5":
answer="D" + answer
if n[len(n)-3]=="6":
answer="DC"+answer
if n[len(n)-3]=="7":
answer="DCC" + answer
if n[len(n)-3]=="8":
answer="DCCC" + answer
if n[len(n)-3]=="9":
answer="CM"+answer
if x>=4:
if n[len(n)-4]=="1":
answer="M" + answer
if n[len(n)-4]=="2":
answer="MM" + answer
if n[len(n)-4]=="3":
answer="MMM"+answer
return answer
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. 17, 2016
Comments: