Menu Close

Convert Numbers into Roman Numerals

Romanizer
Convert numbers into roman numerals.

Example
numbers = [1,49,23]
Looking at the conversions above, 1 is represented as I(capital I which is roman number), 48 is 40 + 9, so XLIX, and 23 is XXIII.
The return values are [‘I’,’XLIX’,’XXIII’].

Explanation:
Input: [1,2,3,4,5]

1 corresponds to roman numeral I
2 corresponds to roman numeral II
3 corresponds to roman numeral III
4 corresponds to roman numeral IV
5 corresponds to roman numeral V

Output: [‘I’,’II’,’III’,’IV’,’V’]

dict={'I':1,'II':2,'III':3,'IV':4,'V':5,'VI':6,'VII':7,'VIII':8,'IX':9,'X':10,'XL':40,
      'L':50,'XC':90,'C':100,'CD':400,'D':500,'CM':900,'M':1000}
val=sorted(list(dict.values()),reverse=True)
Number=list(map(int,input('Enter any numbers : ').split(' ')))
L=[]
for x in Number:
    i=0
    str=''
    while x!=0:
        if i < len(val):
            if val[i]<=x:
                x=x-val[i]
                str+=list(dict.keys())[list(dict.values()).index(val[i])]
            else:
                i+=1
        else:
            break
    print(str)
#you can use string to append all values to display at once.

Sample Output Image ?

Input_1:
Enter any numbers : 1 49 23

Output:
I
XLIX
XXIII


Input_2:
Enter any numbers : 1 2 3 4 5

Output:

I
II
III
IV
V


Input_3:
Enter any numbers : 75 80 99 100 50

Output:

LXXV
LXXX
XCIX
C
L


Morae Q!