-
-
Save amankharwal/4ea5fc3efbe8b522dc340de8f72dbbd9 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
tallies = { | |
'I': 1, | |
'V': 5, | |
'X': 10, | |
'L': 50, | |
'C': 100, | |
'D': 500, | |
'M': 1000, | |
# specify more numerals if you wish | |
} | |
def RomanNumeralToDecimal(romanNumeral): | |
sum = 0 | |
for i in range(len(romanNumeral) - 1): | |
left = romanNumeral[i] | |
right = romanNumeral[i + 1] | |
if tallies[left] < tallies[right]: | |
sum -= tallies[left] | |
else: | |
sum += tallies[left] | |
sum += tallies[romanNumeral[-1]] | |
return sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment