python beginner 2026-11-17 終了

Roman numerals

Write to_roman(n) that turns a whole number from 1 to 3999 into Roman numerals.

  • Use the subtractive forms: 4 is "IV", 9 is "IX", 40 is "XL", 900 is "CM".
  • Raise ValueError for numbers outside 1–3999.

Acceptance criteria

  • to_roman(1994) returns "MCMXCIV".
  • The tests at the bottom print All tests passed.

Hint: walk a table of (value, symbol) pairs from largest to smallest.

これまでに 0 人が解きました。

python
エディターCtrl + Enter

            
        

テストが "All tests passed" と表示すると、このブラウザーでチャレンジが解決済みになります。

解答をレビューに提出