Created
February 14, 2022 17:01
-
-
Save TheRolfFR/3b68a6034c7381e040c16fcda86d0f56 to your computer and use it in GitHub Desktop.
Number to roman numeral converter
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
romlist = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"] | |
numlist = [1000,900,500,400,100,90,50,40,10,9,5,4,1] | |
number = int(input("Enter integer > 0: ")) | |
rn = [] | |
numlist_index = 0 | |
# a number should | |
while number > 0: | |
# add the roman numeral while it "fits" | |
if numlist[numlist_index] <= number: | |
rn.append(romlist[numlist_index]) # add numeral to list | |
number -= numlist[numlist_index] # remove amount from number | |
else: | |
numlist_index += 1 # else move to smaller one | |
print(rn) | |
print(''.join(rn)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment