Last active
February 28, 2021 09:49
-
-
Save Beneboe/ced4dd97b3ce6dcecbe77d74cfef4cee to your computer and use it in GitHub Desktop.
Convert to roman numeral
This file contains hidden or 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
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