20+ Python Decimal to Roman Converters

This post contains a total of 20+ Hand-Picked Python Decimal to Roman converter examples with source code. All the Decimal to Roman converters are made using Python programming langauge.

You can use the source code of these programs for educational use with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Rull Deef 🐺

Made by Rull Deef 🐺. Simple Python program to convert decimal number to roman. Enter decimal positive number up to 3999. ( Source )

dec = list(map(int, input()))[::-1]
syms  = ('IV', 'XL', 'CD', 'M-')
nsyms = ('XL', 'CD', 'M-', '--')
rom = ''

for (d, s, n) in zip(dec, syms, nsyms):
  if d in (1, 2, 3):
    rom = s[0] * d + rom
  elif d == 4:
    rom = s + rom
  elif d in (5, 6, 7, 8):
    rom = s[1] + s[0] * (d - 5) + rom
  elif d == 9:
    rom = s[0] + n[0] + rom

print(rom)

2. By Ann

Made by Ann. ( Source )



def to_roman(value):    
    if not value.isdigit():
        return "We can't convert non-int characters."
        
    value = int(value)
    if value <= 0:
        return "We can't convert negative integer to roman ;("

    roman = {"M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100, "XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5, "IV": 4,  "I": 1}
    
    result = str()
    for key in roman:
        how_many = value // roman[key]
        value -= roman[key] * how_many
        
        if how_many > 0:
            result += key * how_many

    return result 


print(to_roman(input()))
            
    
    

3. By Reem Mansour

Made by Reem Mansour. Program to convert decimal numbers to roman numbers. ( Source )

rom_num = [(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')]

def num_to_roman(number):
    roman=''
    while number > 0:
        for i,j in rom_num:
            while number >= i:
                roman += j
                number -= i
    return roman
    
number = int(input("Enter any number :"))
print(number)
#x = num_to_roman(number)
print("Roman number of", number , "is :",num_to_roman(number))

4. By Ram

Made by Ram. ( Source )

source = {
	1:"I",
	2:"II",
	3:"III",
	4:"IV",
	5:"V",
	6:"VI",
	7:"VII",
	8:"VIII",
	9:"IX",
	10:"X",
	50:"L",
	100:"C",
	500:"D",
	1000:"M"
		
}

value = int(input("What is your decimal number : "))
print(value , "\n")

try:
	print(source[value])
except:
	numeral = ""
	while value > 0:
		while value > 999:
			numeral = numeral + source[1000]
			value -= 1000
		while value > 499:
			numeral = numeral + source[500]
			value -= 500
		while value > 99:
			numeral = numeral + source[100]
			value -= 100
		while value > 49:
			numeral = numeral + source[50]
			value -= 50
		while value > 9:
			numeral = numeral + source[10]
			value -= 10
		if value == 0:
			print("Your new Roman numeral number is",numeral)
		else:
			numeral = numeral + source[value]
			value = 0
			print("Your new Roman numeral number is",numeral)

5. By Stefano De Angelis

Made by Stefano De Angelis. ( Source )

#Decimal to Roman CONVERTER
#Long code but very straight forward

try:
 x = int(input())
 rN = ""
 
 while x >= 1000:
  rN += "M"
  x -= 1000
 if x >= 900:
  rN += "CM"
  x -= 900
 while x >= 500:
  rN += "D"
  x -= 500
 if x >= 400:
  rN += "CD"
  x -= 400
 while x >= 100:
  rN += "C"
  x -= 100
 if x >= 90:
  rN += "XC"
  x -= 90
 while x >= 50:
  rN += "L"
  x -= 50
 if x >= 40:
  rN += "XL"
  x -= 40
 while x >= 10:
  rN += "X"
  x -= 10
 if x >= 9:
  rN += "IX"
  x -= 9
 while x >= 5:
  rN += "V"
  x -= 5
 if x >= 4:
  rN += "IV"
  x -= 4
 while x >= 1:
  rN += "I"
  x -= 1
  
 print(rN)
 
except:
 print("Enter an integer number!")

finally:
 print("\n\nProgram executed.")

6. By Prashant Pal

Made by Prashant Pal. ( Source )

b=int(input())
a=[]
n=b
while(n!=0):
    if n>=1000:
        m=n//1000
        n%=1000
        str="M"*m
        a.append(str)
    elif n<1000 and n>=900:
        m=n//900
        n%=900
        str="CM"*m
        a.append(str)
    elif n<900 and n>=500:
        m=n//500
        n%=500
        str="D"*m
        a.append(str)
    elif n<500 and n>=400:
        m=n//400
        n%=400
        str="CD"*m
        a.append(str)
    elif n<400 and n>=100:
        m=n//100
        n%=100
        str="C"*m
        a.append(str)
    elif n<100 and n>=90:
        m=n//90
        n%=90
        str="XC"*m
        a.append(str)
    elif n<90 and n>=50:
        m=n//50
        n%=50
        str="L"*m
        a.append(str)
    elif n<50 and n>=40:
        m=n//40
        n%=40
        str="XL"*m
        a.append(str)
    elif n<40 and n>=10:
        m=n//10
        n%=10
        str="X"*m
        a.append(str)
    elif n<10 and n>=9:
        m=n//9
        n%=9
        str="IX"*m
        a.append(str)
    elif n<9 and n>=5:
        m=n//5
        n%=5
        str="V"*m
        a.append(str)
    elif n<5 and n>=4:
        m=n//4
        n%=4
        str="IV"*m
        a.append(str)
    elif n<4 and n>=1:
        m=n//1
        n%=1
        str="I"*m
        a.append(str)
print(b,":","".join(a))

7. By Andy Pandy

Made by Andy Pandy. ( Source )

#Roman Numerals are based on the following symbols:
#I = 1
#V = 5
#X = 10
#L = 50
#C = 100
#D = 500
#M = 1000

dec = input()
romM = ""
romC = ""
romX = ""
romI = ""

if len(dec) > 3:
	decM = int(dec[:-3])
	romM = "M" * decM
	
if len(dec) > 2:
	decC = int(dec[-3:-2])
	if decC == 0 or decC == 1 or decC == 2 or decC == 3:
		romC = "C" * decC
	elif decC == 4:
		romC = "CD"
	elif decC == 5 or decC == 6 or decC == 7 or decC == 8:
		romC = "D" + ((decC-5) * "C")
	elif decC == 9:
		romC = "CM"
		
if len(dec) > 1:
	decX = int(dec[-2:-1])
	if decX == 0 or decX == 1 or decX == 2 or decX == 3:
		romX = "X" * decX
	elif decX == 4:
		romX = "XL"
	elif decX == 5 or decX == 6 or decX == 7 or decX == 8:
		romX = "L" + ((decX-5) * "X")
	elif decX == 9:
		romX = "XC"
		
decI = int(dec[-1:])
if decI == 0 or decI == 1 or decI == 2 or decI == 3:
	romI = "I" * decI
elif decI == 4:
	romI = "IV"
elif decI == 5 or decI == 6 or decI == 7 or decI == 8:
	romI = "V" + ((decI-5) * "I")
elif decI == 9:
	romI = "IX"

rom = "{0}{1}{2}{3}".format(romM, romC, romX, romI)

print("The roman numeral for {0} is {1}.".format(dec, rom))

8. By Lorenzo

Made by Lorenzo. ( Source )

#Base
u = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']
d = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC']
c = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM']
m = ['', 'M', 'MM', 'MMM']

number = [input('Write the number that will be converted from decimal to romans:')]

#Code
if str(number[0]).isnumeric() == False:
  print('\nIt isn\'t an integer number')
else:
  i = int(number[0])
  s = str(i)
  if i > 3999 or i < 1:
    print('\nThe number needs to be higger than 1 and lower than 3999. However, your number is '+s+'. Try again.')
  elif i >= 1 and i <= 9:
    print('\nYour number in romans is:\n'+u[i])
  elif i >= 10 and i <= 99:
    n1 = int(number[0][0])
    n2 = int(number[0][1])
    print('\nYour number in romans is:\n'+d[n1]+u[n2])
  elif i >= 100 and i <= 999:
    n1 = int(number[0][0])
    n2 = int(number[0][1])
    n3 = int(number[0][2])
    print('\nYour number in roman is:\n'+c[n1]+d[n2]+u[n3])
  elif i >= 1000 and i<= 3999:
    n1 = int(number[0][0])
    n2 = int(number[0][1])
    n3 = int(number[0][2])
    n4 = int(number[0][2])
    print('\nYour number in roman is:\n'+m[n1]+c[n2]+d[n3]+u[n4])

9. By Tai Duc Pham

Made by Tai Duc Pham. This program will input your decimal number and convert it into Roman numeral. ( Source )


from collections import OrderedDict

def write_roman (num) :
    roman = OrderedDict()
    roman[1000] = 'M'
    roman[900] = 'CM'
    roman[500] = 'D'
    roman[400] = 'CD'
    roman[100] = 'C'
    roman[90] = 'XC'
    roman[50] = 'L'
    roman[40] = 'XL'
    roman[10] = 'X'
    roman[9] = 'IX'
    roman[5] = 'V'
    roman[4] = 'IV'
    roman[1] = 'I'
    
    def roman_num(num):
        for r in roman.keys():
            x, y = divmod(num, r)
            yield roman[r] * x
            num -= (r * x)
            if num > 0:
                roman_num(num)
            else:
                break
            
    return ''.join([a for a in roman_num(num)])

x = int(input('put your number here (not larger than 10000) \n'))

result = write_roman(x)

print('your number is {} , convert to Roman numeral format will be {}'.format(x, result))

10. By Antu Acharjee

Made by Antu Acharjee. Roman numerals generator: 1 = I, 4 = IV, 20 = XX. ( Source )


rom = {1:'I', 4:'IV', 5:'V', 9:'IX', 10:'X', 40:'XL', 50:'L', 90:'XC', 100:'C',400:'CD', 500:'D', 900:'CM', 1000:'M', 4000:'M|V ', 5000:'|V ', 9000:'|IX ', 10000:'|X '}

for i in range(2, 11):
    if i < 4:
        rom[i] = i*'I'
    elif 5 < i < 9:
        rom[i] = rom[5] + (i-5)*'I'

def units(y):
    if y < 4:
        unit = y*'I'
    elif 5 < y < 9:
        unit = rom[5] + (y-5)*'I'
    else:
        unit = rom[y]
    return unit
            
def tens(x):
    if 0 <= x < 10:
        decs = units(x)
    elif 10 <= x < 40:
        decs = int(str(x)[0])*rom[10] + units(int(str(x)[1]))
    elif 40 <= x < 50:
        decs = rom[40] + units(int(str(x)[1]))
    elif 50 <= x < 90:
        decs = rom[50] + (int(str(x)[0])-5)*rom[10] + units(int(str(x)[1]))
    elif 90 <= x < 100:
        decs = rom[90] + units(int(str(x)[1]))
    return decs
        
def hundreds(x):
    if 0 <= x < 100:
        hund = tens(x)
    elif 100 <= x < 400:
        hund = int(str(x)[0])*rom[100] + tens(int(str(x)[1] + str(x)[2]))
    elif 400 <= x < 500:
        hund = rom[400] + tens(int(str(x)[1] + str(x)[2]))
    elif 500 <= x < 900:
        hund = rom[500] + (int(str(x)[0])-5)*rom[100] + tens(int(str(x)[1] + str(x)[2]))
    elif 900 <= x < 1000:
        hund = rom[900] + tens(int(str(x)[1] + str(x)[2]))
    return hund
def thousands(x):
    if 0 <= x < 1000:
        thou = hundreds(x)
    elif 1000 <= x < 4000:
        thou = int(str(x)[0])*rom[1000] + hundreds(int(str(x)[1] + str(x)[2] + str(x)[3]))
    elif 4000 <= x < 5000:
        thou = rom[4000] + hundreds(int(str(x)[1] + str(x)[2] + str(x)[3]))
    elif 5000 <= x < 9000:
        thou = rom[5000] + (int(str(x)[0])-5)*rom[1000] + hundreds(int(str(x)[1] + str(x)[2] + str(x)[3]))
    elif 9000 <= x < 10000:
        thou = rom[9000] + hundreds(int(str(x)[1] + str(x)[2] + str(x)[3]))
    return thou
            
x = int(input('your decimal format number(max limit is 10000): \n'))

if len(str(x)) == 1:
    roman = units(x)
elif len(str(x)) == 2:
    roman = tens(x)
elif len(str(x)) == 3:
    roman = hundreds(x)
elif len(str(x)) == 4:
    roman = thousands(x)
elif x == 10000:
    roman = rom[10000]

print('{} ==> {}(Roman numerals format)'. format(x, roman))

11. By jiangyewen

Made by jiangyewen. ( Source )

romanchar="IVXLCDM"
a=input()
print(a)
d=len(a)
z=[]
def dectoroman(x,y,z):
    if (x%5==4):
        z.insert(0,romanchar[y]+romanchar[(x//5+y+1)])
    else:
        z.insert(0,(x//5)*romanchar[y+(x//5)]+(x%5)*romanchar[y])
    return z
while (d>0):
    dectoroman(int(a[d-1]),(len(a)-d)*2,z)
    d-=1
for i in z:
    print(i,end="")

12. By Pixie

Made by Pixie. The program is simple. Enter a Decimal number, you get it’s Roman Numeral equivalent, or enter a Roman Number and get it’s Decimal equivalent. ( Source )


#Roman Numerals Helper


"""

Changelog:-

12/7/17=>Published code

16/7/17=>Invalid Roman Numerals like IM, VIIIII etc. are handled instead of giving a numerical answer.
"""

def encoder(num):
    roman,s,decimal= ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"],"",[1000,900,500,400,100,90,50,40,10,9,5,4,1]
    for i in range(13):
           while num >= decimal[i]:
                  num = num-decimal[i]
                  s = s+roman[i];
    return s

def decoder(r):
    k=r
    if r=="":return "Don't leave the input blank"
    roman,s= {"M":1000,"CM":900, "D":500, "CD":400, "C":100, "XC":90, "L":50, "XL":40, "X":10, "IX":9, "V":5, "IV":4, "I":1},0
    while r!="":
        if r[:2] in roman:a,r=r[:2],r[2:]
        elif r[0] in roman:a,r=r[0],r[1:]
        else: return "Enter proper Decimal/Roman number as input"
        s+=roman[a]
    return s if encoder(int(s))==k else "Not a valid Roman Numeral"
    
a=input()
try:print(encoder(int(a)))
except:print(decoder(a.upper())) 

13. By Olusegun Abayomi

Made by Olusegun Abayomi. ( Source )

"""
The program converts decimals to Roman Numeral"""

def numeralCheck(digit):
	if len(digit) == 1:
		i = (" ".join(digit))
		s = int(i)
		if s == 0:
			return("")
		elif s > 0 and s <= 3:
			return("I" * s)
		elif s == 4:
			return("IV")
		elif s == 5:
			return("V")
		elif s > 5 and s <= 8:
			k = (s - 5)
			return("V" + ("I"*k))
		else:
			return("IX")
	elif len(digit) == 2:
		
		E = ""
		for i in digit:
			if len(i) == 2:
				j = int(i)
				if j == 0:
					E += ""
				elif j == 10:
					E += "X"
				elif j == 20:
					E += "XX"
				elif j == 30:
					E += "XXX"
				elif j == 40:
					E += "XL"
				elif j == 50:
					E += "L"
				elif j == 60:
					E += "LX"
				elif j == 70:
					E += "LXX"
				elif j == 80:
					E += "LXXX"
				else:
					E += "XC"
			else:
				s = int(i)
				if s == 0:
					E += ""
				elif s > 0 and s <= 3:
					E +=("I" * s)
				elif s == 4:
					E +=("IV")
				elif s == 5:
					E +=("V")
				elif s > 5 and s <= 8:
					k = (s - 5)
					E +=("V" + ("I"*k))
				else:
					E +=("IX")
		return(E)

	elif len(digit) == 3:
		E = ""
		print(3)
		for i in digit:
			if len(i) == 3:
				j = int(i)
				if j == 0:
					E += ""
				elif j == 100:
					E += "C"
				elif j == 200:
					E += "CC"
				elif j == 300:
					E += "CCC"
				elif j == 400:
					E += "CD"
				elif j == 500:
					E += "D"
				elif j == 600:
					E += "DC"
				elif j == 700:
					E += "DCC"
				elif j == 800:
					E += "DCCC"
				else:
					E += "CM"
			elif len(i) == 2:
				j = int(i)
				if j == 0:
					E += ""
				elif j == 10:
					E += "X"
				elif j == 20:
					E += "XX"
				elif j == 30:
					E += "XXX"
				elif j == 40:
					E += "XL"
				elif j == 50:
					E += "L"
				elif j == 60:
					E += "LX"
				elif j == 70:
					E += "LXX"
				elif j == 80:
					E += "LXXX"
				else:
					E += "XC"
			else:
				s = int(i)
				if s == 0:
					E += ""
				elif s > 0 and s <= 3:
					E +=("I" * s)
				elif s == 4:
					E +=("IV")
				elif s == 5:
					E +=("V")
				elif s > 5 and s <= 8:
					k = (s - 5)
					E +=("V" + ("I"*k))
				else:
					E +=("IX")
		return(E)
	elif len(digit) == 4:
		
		E = ""
		for i in digit:
			if len(i) == 4:
				j = int(i)
				if j == 0:
					E += ""
				elif j == 1000:
					E += "M"
				elif j == 2000:
					E += "MM"
				elif j == 3000:
					E += "MMM"
				elif j == 4000:
					E += "Mv"

				else:
					return("The figure is above the programmed level")
			elif len(i) == 3:
				j = int(i)
				if j == 0:
					E += ""
				elif j == 100:
					E += "C"
				elif j == 200:
					E += "CC"
				elif j == 300:
					E += "CCC"
				elif j == 400:
					E += "CD"
				elif j == 500:
					E += "D"
				elif j == 600:
					E += "DC"
				elif j == 700:
					E += "DCC"
				elif j == 800:
					E += "DCCC"
				else:
					E += "CM"
			elif len(i) == 2:
				j = int(i)
				if j == 0:
					E += ""
				elif j == 10:
					E += "X"
				elif j == 20:
					E += "XX"
				elif j == 30:
					E += "XXX"
				elif j == 40:
					E += "XL"
				elif j == 50:
					E += "L"
				elif j == 60:
					E += "LX"
				elif j == 70:
					E += "LXX"
				elif j == 80:
					E += "LXXX"
				else:
					E += "XC"

			else:
				s = int(i)
				if s == 0:
					E += ""
				elif s > 0 and s <= 3:
					E +=("I" * s)
				elif s == 4:
					E +=("IV")
				elif s == 5:
					E +=("V")
				elif s > 5 and s <= 8:
					k = (s - 5)
					E +=("V" + ("I"*k))
				else:
					E +=("IX")
		return(E)


def solution(n):
	# TODO convert int to roman string
	book = []
	counter = 1
	pen = str(n)
	for i in pen:
		book.append(i+((len(pen)-counter)*("0")))
		counter += 1
	return(numeralCheck(book))





print(solution(2148))

14. By David Avetian

Made by David Avetian. ( Source )

Rom_to_Dec = {
    1: 'I', 2: 'II', 3: 'III', 5: 'V', 4: 'IV',
    6: 'VI', 7: 'VII', 8: 'VIII', 10: 'X',
    9: 'IX', 20: 'XX', 30: 'XXX', 50: 'L', 40: 'XL',
    60: 'LX', 70: 'LXX', 80: 'LXXX', 100: 'C',
    90: 'XC', 200: 'CC', 300: 'CCC', 500: 'D', 400: 'CD',
    600: 'DC', 700: 'DCC', 800: 'DCCC', 900: 'CM'}
# it is sorted like this because
# we seek for Romans 4, 9, 40, 90, etc
# before  5, 10, 50, 100, and so on
# for higher numbers dict should be adjusted in the same pattern

num = input()

try:
    """
    This part converts Decimals to Romans
    """
    N = int(num)
    Roman = []  # here Roman numerals are kept
    i = 0  # an order of current iteration (as in 10 ** 0 and so on)
    while N > 0:
        """
        The main idea is that we convert decimals into romans
        from right to left and so does this program
        """
        Decimal = N % 10  # here one gets the last number
        Decimal *= 10 ** i
        # gets an actual number from dict
        # considering all previous numbers from the right are already away
        N //= 10  # takes away the last number on the right
        i += 1    # upgrades an order of iteration
        if Decimal >= 1000:
            """
            As there are no special Roman Numerals after 1000
            it's better to count M's separately
            If you want to use other symbols for 5000, 10000 and more
            You can adjust the initial dict
            """
            k = Decimal // 1000
            Roman.append('M' * k)
        elif Decimal == 0:
            continue
        else:
            Roman.append(Rom_to_Dec[Decimal])
    print(num, 'in Romans is', ''.join(Roman[::-1]))

except ValueError:
    """
    This part reverses the original dict
    """
    _values = []  # keeps values from original dictionary
    _keys = []    # keeps its keys

    for i in Rom_to_Dec:
        """
        Takes values and keys from original dict
        """
        _values.append(Rom_to_Dec[i])
        _keys.append(i)
    """
    And reverses them joining in new dict
    """
    _values.reverse()
    _keys.reverse()
    # reversed dict:
    Dec_to_Rom = {_values[i]: _keys[i] for i in range(len(_values))}
    # the main idea here to convert numbers formleft to right

    """
    This part converts Romans to Decimals
    """
    res = 0  # to be the final result
    num = num.upper()  # just in case if some letters are not in caps
    mem = num  # memorizing input
    for i in range(len(num)):
        """
        As there are no special Roman Numerals after 1000
        it's better to count M's separately
        """
        if num[i] == 'M':
            res += 1000
        else:
            # if not this CM would be 1900 and so on
            break
    for v in Dec_to_Rom:
        if v in num:
            res += Dec_to_Rom[v]
            num = num.lstrip(v)  # this is done to avoid multiple counting

    if res == 0 or len(num) > 0:
        print(mem, 'either isn\'t a Roman number or doesn\'t follow the rules')
    else:
        print(mem, 'in decimals is', res)

15. By John Galas

Made by John Galas. This program only works with numbers up to 200. ( Source )


num = float(input("Num: "))

def get_rn(num):
    rn = ''
    if num % 100 >= 0 and num >= 100:
        C = 'C' * int(num/100)
        rn += C
    if 9 >= (num+10) % 100 >= 0:
        rn += 'XC'
    if num % 50 >= 0 and num >= 50 and num < 90:
        L = 'L' * int(num/50)
        rn += L
    elif num % 50 >= 0 and num >= 150 and num < 190:
        L = 'L' * int((num-100)/50)
        rn += L
    if 9 >= ((num+10) % 50) >= 0 and num < 90:
        rn += 'XL'
    elif 9 >= ((num+10) % 50) >= 0 and 190 > num > 100:
        rn += 'XL'
    if num % 10 >= 0 and num >= 10 and num < 40:
        X = 'X' * int(num/10)
        rn += X
    elif num % 10 >= 0 and num > 50 and num < 90:
        X = 'X' * int((num-50)/10)
        rn += X
    elif num % 10 >= 0 and num > 100 and num < 140:
        X = 'X' * (int((num-100)/10))
        rn += X
    elif num % 10 >= 0 and num > 150 and num < 190:
        X = 'X' * (int((num-150)/10))
        rn += X
    if (num+1) % 10 == 0:
        rn += 'IX'
    if num % 5 >= 0 and num % 10 >= 5 and (num+1) % 10 != 0 and (num+1) % 5 != 0:
        rn += 'V'
    if (num+1) % 5 == 0 and (num+1) % 10 != 0:
        rn += 'IV'
    if num % 5 != 0 and num % 10 != 0 and (num+1) % 10 != 0 and (num+1) % 5 != 0 :
        I = 'I' * (num%5)
        rn += I
    



    return rn

num_string = str(num)
num_string_split = num_string.split(".")
print(num_string_split)
num1 = int(num_string_split[0])
num2 = int(num_string_split[1])
rn_deci = get_rn(num1) + '.' + get_rn(num2)
print(rn_deci)

16. By Álex Velasco

Made by Álex Velasco. ( Source )



def selectRoman(num,dec):
    if(dec==1):
        one="I"
        five="V"
        ten="X"
    elif(dec==10):
        one="X"
        five="L"
        ten="C"
    elif(dec==100):
        one="C"
        five="D"
        ten="M"
    else:
        m=""
        for loop in range(int(int(num)*(dec/1000))):
            m=m+"M"
            
        return m
        
    if(num=="1"):
        return one
    elif(num=="2"):
        return one+one
    elif(num=="3"):
        return one+one+one
    elif(num=="4"):
        return one+five
    elif(num=="5"):
        return five
    elif(num=="6"):
        return five+one
    elif(num=="7"):
        return five+one+one
    elif(num=="8"):
        return five+one+one+one
    elif(num=="9"):
        return one+ten
    return ""
def decimaltoRoman (numbers):
    print (numbers)
    i=10**(len(numbers)-1)
    str=""
    for number in numbers:
        str+=selectRoman(number,i)
        i=i/10
    return str
def main():
    x=decimaltoRoman(input("Converting the number: "))
    print(x)
main()

17. By Maria

Made by Maria. ( Source )

#Decimal number to roman

def decimal2roman(n):
    dict = ((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 = ''
    while n > 0:
        for i, r in dict:
            while n >= i:
                roman += r
                n -= i
    return roman
    
print(decimal2roman(int(input())))

18. By Lucas Pardo

Made by Lucas Pardo. ( Source )

#Inspired by LukArToDo's code: https://code.sololearn.com/c95Y62c4p1dV/?ref=app
#Inspired but not copied, this is my own way.

n = int(input())
roman = {1000:"M", 500:"D", 100:"C", 50:"L", 10:"X", 5:"V", 1:"I"}
nums = [1000, 500, 100, 50, 10, 5, 1]

if n >= 4000:
    print("Please input in the range (1-3999).")
else:
    res = ""
    for i in range(len(nums)):
        digit = n // nums[i]
        if digit == 4:
            if res[-1] == "L":
                aux = "XC"
            elif res[-1] == "V":
                aux = "IX"
            elif res[-1] == "D":
                aux = "CM"
            else:
                aux = roman[nums[i]] + roman[nums[i-1]]
            res = res[:-1] + aux
        else:
            res += roman[nums[i]]*digit
        n %= nums[i]
    print("The roman number is", res)
            

19. By Selim Sayma

Made by Selim Sayma. Simple decimal to roman converter. ( Source )

def solution(number):
    result = []
    while number >= 1000:
        result.append('M')
        number -= 1000
    result = result
    number = number
    while number < 1000 and number >= 100:
        if number >= 900:
            result.append('CM')
            number -= 900
        if number >= 500:
            result.append('D')
            number -= 500
        if number >= 400:
            result.append('CD')
            number -= 400
        if number >= 100:
            result.append('C')
            number -= 100
    result = result
    number = number
    while number < 100 and number >= 10:
        if number >= 90:
            result.append('XC')
            number -= 90
        if number >= 50:
            result.append('L')
            number -= 50
        if number >= 40:
            result.append('XL')
            number -= 40
        if number >= 10:
            result.append('X')
            number -= 10
    result = result
    number = number
    if number == 9:
        result.append('IX')
    if number == 8:
        result.append('VIII')
    if number == 7:
        resut.append('VII')
    if number == 6:
        result.append('VI')
    if number == 5:
        result.append('V')
    if number == 4:
        result.append('IV')
    if number == 3:
        result.append('III')
    if number == 2:
        result.append('II')
    if number == 1:
        result.append('I')      
    return (''.join(result))
    
number = int(input())

print(solution(number))

20. By Ava Thrasher

Made by Ava Thrasher. ( Source )

x = int(input ("Your number was:"))


if x == 1:
    print ("I")
    
elif x == 2:
    print ("II")
    
elif x == 3:
    print ("III")
    
elif x == 4:
    print ("VI")
    
elif x == 5:
    print ("v")
    
elif x == 6:
    print ("VI")
    
elif x == 7:
    print ("VII")
    
elif x == 8:
    print ("VIII")
    
elif x == 9:
    print ("IX")
    
elif x == 10:
    print ("X")
    
else:
    print ("Number is greater than 10")

21. By Mike Buttery

Made by Mike Buttery. Decimal to Roman Converter, Enter an integer between 1 and 3999. ( Source )


def dectoroman(n):
    if 1 < n < 4000:
        number = n
        roman = [
            (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"),
        ]

        result = ""
        for i in roman:
            count = number // i[0]
            number -= i[0] * count
            result += i[1] * count
        return n, result
    else:
        return "Requires an integer between 1 and 3999", ""


d, r = dectoroman(int(input()))
print("Decimal: {}\nRoman: {}".format(d, r))