Skip to content

Instantly share code, notes, and snippets.

@browneye1826
Created February 13, 2022 08:12
Show Gist options
  • Save browneye1826/70f3ae1f52bfad11fd4f6648510d7520 to your computer and use it in GitHub Desktop.
Save browneye1826/70f3ae1f52bfad11fd4f6648510d7520 to your computer and use it in GitHub Desktop.
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