Editor

Roman Numerals

Intermediate · Write the code · from 50 Python Practice Problems with Instant Answer Checking (Beginner to Advanced)

From the lesson: 50 Python Practice Problems with Instant Answer Checking (Beginner to Advanced)

Fifty problems, each with a code editor and real tests. Write your solution, press Check, and see exactly which cases pass. Stuck? Hints reveal one at a time, and the solution unlocks once you have checked at least once. Your code and progress are saved in this browser.

Read the lesson

Write to_roman(n) that converts an integer from 1 to 3999 into Roman numerals, including the subtractive forms like IV (4), IX (9), XL (40) and CM (900).

def to_roman(n):
pass
Solution unlocks after your first Check

What Check runs

Your code runs first, then each of these lines. The output must match exactly.

RunsExpected output
to_roman(4)'IV'
to_roman(1994)'MCMXCIV'

More practice problems

All Python exercises · 50 practice problems