Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Bartlomiej_Szal
def decToRom(dec):
romList = ['M', 'D', 'C', 'L', 'X', 'V', 'I']
unusualRomList = ["CM", "CD", "XC", "XL", "IX", "IV", "I"]
intList = [1000, 500, 100, 50, 10, 5, 1]
unusualIntList = [900, 400, 90, 40, 9, 4, 1]
rom = "";
i = 0;
while (dec > 0):
if (dec >= intList[i]):
dec -= intList[i]
rom += romList[i]
elif (dec >= unusualIntList[i]):
dec -= unusualIntList[i];
rom += unusualRomList[i];
else:
i += 1;
return rom
def checkio(data):
return decToRom(data)
Oct. 8, 2016
Comments: