Python conversion from Roman to Arabic
Write a program that converts Roman numerals into ordinary numbers. Here are the conversions: M=1000, D=500, C=100, L=50, X=10, V=5 I=1. Don’t forget about things like IV being 4 and XL being 40.
numerals = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} U = [] for i in numerals: U.append(i) enter_num = input('Enter the number for coversion from romans to arabic numbers: ') L = [] L = list(enter_num) t = 0K = [] O = [] minus = [] indexi_O = [] for i in L: K.append(numerals[i]) for i in K: O.append(int(i)) for i in range(len(O)): if 0 <= i <len(O)-1 and O[i] < O[i+1]: t = O[i+1] - O[i] minus.append(t) c = i + 1 p = i indexi_O.append(c) indexi_O.append(p) t = 0indexi_O.sort() for i in range(len(indexi_O)-1, -1, -1): del O[indexi_O[i]] print(enter_num, ' = ', sum(O) + sum(minus))
SOLUTION: Enter the number for coversion from romans to arabic numbers: MMDCCXCIX MMDCCXCIX = 2799
Коментари
Постави коментар