Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by bpvital
#Strings
NUM1 = ["","I","II","III","IV","V","VI","VII","VIII","IX"]
NUM10 = ["","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"]
NUM100 = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"]
NUM1000 = ["","M","MM","MMM"]
def checkio(data):
#split number into tens into string format, adding leading zeroes.
num = str(data)
while len(num) < 4:
num = "0" + num
#get values from lists, combining and returning final result
return NUM1000[int(num[0])] + NUM100[int(num[1])] + NUM10[int(num[2])] + NUM1[int(num[3])]
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'
Aug. 14, 2014
Comments: