CoreChallenge 16 of 34

Roman numerals

Write to_roman(n) for 1 ≤ n ≤ 3999. Remember the subtractive forms: 4 is IV, 9 is IX, 40 is XL, 90 is XC, 400 is CD, 900 is CM.

Examples
to_roman(1994) → "MCMXCIV"
to_roman(2026) → "MMXXVI"
Exercise

Roman numerals

4 checks
def to_roman(n):
    ...


print(to_roman(1994))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.