Created
February 13, 2022 08:12
-
-
Save browneye1826/70f3ae1f52bfad11fd4f6648510d7520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAP = [ | |
(1000, "M"), | |
(900, "CM"), | |
(500, "D"), | |
(400, "CD"), | |
(100, "C"), | |
(90, "XC"), | |
(50, "L"), | |
(40, "XL"), | |
(10, "X"), | |
(9, "IX"), | |
(5, "V"), | |
(4, "IV"), | |
(1, "I"), | |
] | |
def num2roman(num: int) -> str: | |
"""Digits to Roman numerals convertor | |
Args: | |
num (int): | |
Returns: | |
str: | |
""" | |
roman = "" | |
while num > 0: | |
for i, r in MAP: | |
while num >= i: | |
roman += r | |
num -= i | |
return roman |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment