write a program to convert numbers to roman numbers.

#wap to convert a nos. to equivalent roman no.
number=[1,4,5,9,10,40,50,90,100,400,500,900,1000]
roman=['I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M']
n=int(input("please enter number "))
i=12
s1=''
while n!=0:
    if number[i]<=n:
        s1=s1+roman[i]
        n=n-number[i]
    else:
        i=i-1
print(s1)

   
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\roman number.py
please enter number 54
LIV
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\roman number.py
please enter number 176
CLXXVI
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\roman number.py
please enter number 987
CMLXXXVII
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\roman number.py
please enter number 7
VII
>>> 

Leave a Reply

Back To Top