Roman Numerals
Write a program to convert a non-negative integer
N to its Roman numeral representation.Roman numerals are usually written largest to smallest from left to right.
symbol value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
A number containing several decimal digits is built by appending Roman numeral equivalent for each, from highest to lowest, as in the following examples:
The input will be a single line containing a positive integer N.
The input number not be greater than 104.
Output
The output should be a single line containing representation of Roman Numeral of number N.
See Roman Numerals Table for Symbol and corresponding value.
Sample Input 1
2
Sample Output 1
II
Sample Input 2
1994
Sample Output 2
MCMXCIV
def Roman(number):
numbers = {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'}
rom = ""
for key in numbers.keys():
count = int(number / key)
rom += numbers[key] * count
number -= key * count
return rom
n = int(input())
print(Roman(n))
Comments
Leave a comment