Skip to content

Instantly share code, notes, and snippets.

@itsalljustdata
Created March 22, 2024 02:52
Show Gist options
  • Select an option

  • Save itsalljustdata/fcf96639eab5548e47edadf6ad868de0 to your computer and use it in GitHub Desktop.

Select an option

Save itsalljustdata/fcf96639eab5548e47edadf6ad868de0 to your computer and use it in GitHub Desktop.
Converts an integer value to Roman numerals
def getRoman(theInteger : int, lcase : bool = False):
mappy = [[1,"I"]
,[4,"IV"],[5,"V"]
,[9,"IX"],[10,"X"]
,[40,"XL"],[50,"L"]
,[90,"XC"],[100,"C"]
,[400,"CD"],[500,"D"]
,[900,"CM"],[1000,"M"]
]
# Romans weren't big on decimals...
theInteger = int(theInteger+.5)
retval = ""
for i in reversed(range(len(mappy))):
retval += (mappy[i][1]*(theInteger // mappy[i][0]))
theInteger %= mappy[i][0]
return retval.lower() if lcase else retval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment