Ad
Basic Language Features
Fundamentals
Control Flow

// Change from original fork by adding compatability for Value protection, if the input is not a number, we will cancel rather than crash.

Code
Diff
  • def convert_decimal_roman(number):
        try:
            number = int(number)
        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"}
        
        for key, value in numDct.items():
            str += value * (number // key)
            number %= key
            
        return str
    • def convert_decimal_roman(number):
    • number = int(number)
    • try:
    • number = int(number)
    • 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"}
    • for key, value in numDct.items():
    • str += value * (number // key)
    • number %= key
    • return str