Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- romanNumerals = {"I": 1,
- "V": 5,
- "X": 10,
- "L": 50,
- "C": 100,
- "D": 500,
- "M": 1000,
- }
- def reverse_roman(roman_string):
- solution = 0
- sum = 0
- skipValue = False
- for counter, element in enumerate(roman_string):
- if skipValue:
- skipValue = False
- continue
- if counter+1 < len(roman_string):
- if romanNumerals[roman_string[counter+1]] > romanNumerals[element]:
- sum = romanNumerals[roman_string[counter+1]] - romanNumerals[element]
- solution = solution + sum
- skipValue = True
- continue
- solution = solution + romanNumerals[element]
- return solution
- if __name__ == '__main__':
- #These "asserts" using only for self-checking and not necessary for auto-testing
- assert reverse_roman('VI') == 6, '6'
- assert reverse_roman('LXXVI') == 76, '76'
- assert reverse_roman('CDXCIX') == 499, '499'
- assert reverse_roman('MMMDCCCLXXXVIII') == 3888, '3888'
- print('Great! It is time to Check your code!');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement