Created
March 22, 2024 02:52
-
-
Save itsalljustdata/fcf96639eab5548e47edadf6ad868de0 to your computer and use it in GitHub Desktop.
Converts an integer value to Roman numerals
This file contains hidden or 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
| 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