I\'m trying to write a code that converts a user-inputted integer into its Roman numeral equivalent. What I have so far is:
The point of the generate_
The code for this roman numeral does not check for errors like wrong letters it is just for a perfect roman numeral letters
roman_dict = {'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}
roman = input('Enter the roman numeral: ').upper()
roman_initial = roman # used to retain the original roman figure entered
lst = []
while roman != '':
if len(roman) > 1:
check = roman[0] + roman[1]
if check in roman_dict and len(roman) > 1:
lst.append(check)
roman = roman[roman.index(check[1])+1:]
else:
if check not in roman_dict and len(roman) > 1:
lst.append(check[0])
roman = roman[roman.index(check[0])+1:]
else:
if len(roman)==1:
check = roman[0]
lst.append(check[0])
roman = ''
if lst != []:
Sum = 0
for i in lst:
if i in roman_dict:
Sum += roman_dict[i]
print('The roman numeral %s entered is'%(roman_initial),Sum)