-
-
Save kkoci/a0b73d4ee01b5dd65ea190377602fa2f to your computer and use it in GitHub Desktop.
Roman Numerals Kata - Python 3.6 Dict keys retain input ordering
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
numerals = {"I":1, "V":5, "X":10, "L": 50, "C": 100, "D": 500, "M": 1000 } | |
def convert_roman(input_number): | |
range_flag = None | |
for symbol, integer in numerals.items(): | |
if integer == input_number: return symbol | |
if input_number > integer: | |
range_flag = symbol | |
remaining = input_number - numerals[range_flag] | |
return range_flag + convert_roman(remaining) | |
print(convert_roman(1)) # MCXI | |
print(convert_roman(17)) # XVII | |
print(convert_roman(1111)) # MCXI | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment