Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Lachesis_132296
def checkio(data):
chars = {3000: 'MMM', 2000: 'MM', 1000: 'M', 900: 'CM', 800: 'DCCC', 700:'DCC', 600:'DC', 500: 'D', 400: 'CD', 300:'CCC', 200: 'CC', 100: 'C', 90: 'XC', 80:'LXXX', 70: 'LXX', 60:'LX', 50: 'L', 40: 'XL', 30: 'XXX', 20: 'XX', 10: 'X', 9:'IX', 8: 'VIII', 7: 'VII', 6: 'VI', 5: 'V', 4: 'IV', 3: 'III', 2: 'II', 1: 'I'}
number = ""
digit = 0
decimal = 1
decimal2 = 1
digit2 = 0
num0 = 0
while (data > 0):
digit = data%10
if digit != 0:
number = chars.get(digit*decimal, "error")+ number
data = data//10
decimal *=10
else:
digit2 = 0
decimal2 = 1
while digit2 == 0:
digit2 = data%10
decimal2 *=10
data = data//10
num0 = digit2 * decimal2//10
number = chars.get(num0*decimal, "error") + number
print(num0)
decimal = decimal*decimal2
return 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'
Nov. 19, 2016