Roman Numeral

Back to homepage

Project Overview

Write a program that converts a number to a Roman numeral. This challenge started 2020 Nov 17 and ended 2020 Nov 24.

Submissions

Kat Crawford

numeralDictionary = {
    1 : "I",
    2 : "II",
    3 : "III",
    4 : "IV",
    5 : "V",
    6 : "VI",
    7 : "VII",
    8 : "VIII",
    9 : "IX",
    10 : "X",
    11 : "XI",
    12 : "XII",
    13 : "XIII",
    14 : "XIV",
    15 : "XV",
    16 : "XVI",
    17 : "XVII",
    18 : "XVIII",
    19 : "XIX",
    20 : "XX",
    50 : "L",
    100 : "C",
    500 : "D",
    1000 : "M"
}

try:
    a = int(input("Enter a number  "))
    numeral = numeralDictionary[a]
    print(numeral)

except:
    print("Your input was invalid.")

Landon Kahl

numerals = {1:'I', 2:'II', 3:'III', 4:'IV', 5:'V',
    6:'VI', 7:'VII', 8:'VIII', 9:'IX', 10:'X', 20:'XX', 30:'XXX', 40:'XL',
    50:'L', 60:'LX', 70:'LXX', 80:'LXXX', 90:'XC', 100:'C', 200:'CC', 300:'CCC',
    400:'CD', 500:'D', 600:'DC', 700:'DCC', 800:'DCCC', 900:'CM', 1000:'M'}
x = int(input("Enter any Integer: "))
for key, value in numerals.items():
        if x == key:
                print("Since you typed, " + str(x) + " your roman number is " + str(value))

Benjamin Lowry

symbols = {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"}
try:
    x = int(input("Enter a number. "))
except ValueError:
    print("Invalid input")
    exit(1)
output = ""
for value, symbol in symbols.items():
    while x >= value:
        output += symbol
        x -= value
        print(str(x))
print(output)