# Writing a program to convert a number to roman numeral (Pyth 3)

``````x=int(input('Enter a number: '))
n=x
l=[]
'''*************************************'''
for i in range(4):
l+=[n%10]
n//=10
'''*************************************'''
l.reverse()
s=str(l[0])+'*1000 + '+str(l[1])+'*100 + '+str(l[2])+'*10 + '+str(l[3])
e=''
'''*************************************'''
#for first digit
e+=l[0]*'M'
'''*************************************'''
#for 2nd digit
if l[1]<4:
e+='C'*l[1]
elif l[1]==4:
e+='CD'
elif l[1]==9:
e+='CM'
else:
e+='D'+'C'*(l[1]-5)
'''*************************************'''
#for 3rd digit
if l[2]<4:
e+='X'*l[2]
elif l[2]==4:
e+='XL'
elif l[2]==9:
e+='XC'
else:
e+='L'+'X'*(l[2]-5)
'''*************************************'''
#for last digit
if l[3]<4:
e+='I'*l[3]
elif l[3]==4:
e+='IV'
elif l[3]==9:
e+='IX'
else:
e+='V'+'I'*(l[3]-5)
print('Roman numeral for ',x,' is ',e)
``````

This is the program, which is unfortunately very long. Is there a shorter way to do this? If yes how?