Ad
Basic Language Features
Fundamentals
Control Flow
Code
Diff
  • def convert_decimal_roman(number: int) -> str:
        try:
            number = int(number)
            if number<1 or number >=4000:
                print("Range Error: Number can only be between 1 and 3999.")
                return("Invalid Input")
        except ValueError:
            print("Invalid Input, Value Error")
            return("Invalid Input")
        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"}
        
        decimals = []
        for key, value in numDct.items():
            decimals.append(value * (number // key))
            number %= key
            
        return "".join(decimals)
    • def convert_decimal_roman(number: int) -> str:
    • try:
    • number = int(number)
    • if number<1 or number >=4000:
    • print("Range Error: Number can only be between 1 and 3999.")
    • return("Invalid Input")
    • except ValueError:
    • print("Invalid Input, Value Error")
    • return("Invalid Input")
    • 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"}
    • decimals = []
    • for key, value in numDct.items():
    • decimals.append(value * (number // key))
    • number %= key
    • return "".join(decimals)