IT45200

Untitled

Apr 22nd, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. def integer_to_roman_conversion(x):
  2.     d = {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'}
  3.     resp = ''
  4.     while x>0:
  5.         for i in d:
  6.             if i<=x:
  7.                 resp+=d[i]
  8.                 x=x-i
  9.                 break
  10.     return resp
  11.  
  12.  
  13. try:
  14.     num = int(input("Enter a positive number between 0 and 1000 : "))
  15.     while True:
  16.         if num>0 and num<1000:
  17.             break
  18.         else:
  19.             num = int(input("Enter a positive number between 0 and 1000 : "))
  20.     print(integer_to_roman_conversion(num))
  21.  
  22. except ValueError:
  23.     print("The input must be a number.")
Advertisement
Add Comment
Please, Sign In to add comment