Created
August 13, 2015 05:19
-
-
Save viveksyngh/4f4aa08db022eec4a2eb to your computer and use it in GitHub Desktop.
Integer to roman
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
| __author__ = 'Vivek' | |
| #Convert an integer into Roman Numerals | |
| def intToRoman(A): | |
| value = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] | |
| numerals = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'] | |
| res , i = "", 0 | |
| if A < 1 or A > 3999 : | |
| return res | |
| while A : | |
| res += (A//value[i])*numerals[i] | |
| A %= value[i] | |
| i += 1 | |
| return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment