Ad
Basic Language Features
Fundamentals
Control Flow
Code
Diff
  • def convert_decimal_roman(number):
        number = int(number)
        str = ""
        numDct = {1000: "M",
                  900: "CM",
                  500: "D",
                  400: "CD",
                  100: "C",
                  90: "XC",
                  50: "L",
                  40: "XL",
                  10: "X",
                  9: "IX",
                  5: "V",
                  4: "IV",
                  1: "I"}
    
        for key in numDct:
            while number >= key:
                str += numDct[key]
                number -= key
        return str
    • def convert_decimal_roman(numero):
    • num_romanos_dic = {
    • 1: 'I',
    • 5: 'V',
    • 10: 'X',
    • 50: 'L',
    • 100: 'C',
    • 500: 'D',
    • 1000: 'M'
    • }
    • list_num_rom = [{'key': x, 'value': y} for x, y in num_romanos_dic.items()]
    • size_num = len(numero)
    • output = []
    • for i in range(size_num):
    • num = numero[i:]
    • num_unit = int(num)
    • numextre_izq = int(num[0])
    • pref = []
    • for i in range(1, len(list_num_rom), 2):
    • if num_unit >= list_num_rom[i-1]['key'] and num_unit < list_num_rom[i+1]['key']:
    • pref.append(list_num_rom[i-1]['value'])
    • pref.append(list_num_rom[i]['value'])
    • pref.append(list_num_rom[i+1]['value'])
    • def convert_decimal_roman(number):
    • number = int(number)
    • str = ""
    • numDct = {1000: "M",
    • 900: "CM",
    • 500: "D",
    • 400: "CD",
    • 100: "C",
    • 90: "XC",
    • 50: "L",
    • 40: "XL",
    • 10: "X",
    • 9: "IX",
    • 5: "V",
    • 4: "IV",
    • 1: "I"}
    • if numextre_izq < 4 and numextre_izq > 0:
    • output.append(pref[0]*numextre_izq)
    • if numextre_izq == 4:
    • output.extend(pref[0:2])
    • if numextre_izq == 5:
    • output.append(pref[1])
    • if numextre_izq > 5 and numextre_izq < 9:
    • output.append(pref[1] + pref[0]*(numextre_izq-5))
    • if numextre_izq == 9:
    • output.extend(pref[::2])
    • output = ''.join(output)
    • return output
    • for key in numDct:
    • while number >= key:
    • str += numDct[key]
    • number -= key
    • return str