conversions.roman_numerals¶
Attributes¶
Functions¶
|
Given an integer, convert it to a Roman numeral. |
|
LeetCode No. 13 Roman to Integer |
Module Contents¶
- conversions.roman_numerals.int_to_roman(number: int) str¶
Given an integer, convert it to a Roman numeral. Input must be an integer in the range 1 to 3999. https://en.wikipedia.org/wiki/Roman_numerals >>> tests = {“III”: 3, “CLIV”: 154, “MIX”: 1009, “MMD”: 2500, “MMMCMXCIX”: 3999} >>> all(int_to_roman(value) == key for key, value in tests.items()) True >>> int_to_roman(0) Traceback (most recent call last):
…
ValueError: int_to_roman only accepts integers in the range 1 to 3999, got 0 >>> int_to_roman(-1) Traceback (most recent call last):
…
ValueError: int_to_roman only accepts integers in the range 1 to 3999, got -1 >>> int_to_roman(4000) Traceback (most recent call last):
…
ValueError: int_to_roman only accepts integers in the range 1 to 3999, got 4000 >>> int_to_roman(True) Traceback (most recent call last):
…
TypeError: int_to_roman only accepts integers, got bool
- conversions.roman_numerals.roman_to_int(roman: str) int¶
LeetCode No. 13 Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. https://en.wikipedia.org/wiki/Roman_numerals >>> tests = {“III”: 3, “CLIV”: 154, “MIX”: 1009, “MMD”: 2500, “MMMCMXCIX”: 3999} >>> all(roman_to_int(key) == value for key, value in tests.items()) True
- conversions.roman_numerals.ROMAN = [(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'), (50, 'L'), (40,...¶