Skip to content

Instantly share code, notes, and snippets.

@isennkubilay
Last active January 26, 2021 20:00
Show Gist options
  • Save isennkubilay/23f71705a18c4514a7399ee83412fb82 to your computer and use it in GitHub Desktop.
Save isennkubilay/23f71705a18c4514a7399ee83412fb82 to your computer and use it in GitHub Desktop.
def solution(n):
roman_numerals = {1000:'M',
900: 'CM',
500: 'D',
400: 'CD',
100: 'C',
90: 'XC',
50: 'L',
40: 'XL',
10: 'X',
9: 'IX',
5: 'V',
4: 'IV',
1: 'I'
}
roman_string = ''
for key in sorted(roman_numerals.keys(),reverse=True):
while n >= key:
roman_string += roman_numerals[key]
n -= key
return roman_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment