Skip to content

Instantly share code, notes, and snippets.

@Beneboe
Last active February 28, 2021 09:49
Show Gist options
  • Save Beneboe/ced4dd97b3ce6dcecbe77d74cfef4cee to your computer and use it in GitHub Desktop.
Save Beneboe/ced4dd97b3ce6dcecbe77d74cfef4cee to your computer and use it in GitHub Desktop.
Convert to roman numeral
def to_roman(n):
r = ''
r = 'I' * ((n // 1) % 5) + r
r = 'V' * ((n // 5) % 2) + r
r = 'X' * ((n // 10) % 5) + r
r = 'L' * ((n // 50) % 2) + r
r = 'C' * ((n // 100) % 5) + r
r = 'D' * ((n // 500) % 2) + r
r = 'M' * (n // 1000) + r
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment