Closed OtakuChel closed 2 years ago
I fixed the code, everything works.
BASE = { "I":1, "V":5, "X":10, "L":50, "C":100, "M":1000 }
rim_value = tuple(input('Введите римскую цифру: '))
def transliter(rim_value): x = [] for i in rim_value: y = BASE[i] x.append(y) arab_value = tuple(x) return arab_value
print(transliter(rim_value)) res = transliter(rim_value)
def calc(res): try: sum = 0 for i in range(len(res)): if res[i] >= res[i+1]: sum += res[i] else: sum += res[i+1] - res[i]
except IndexError:
if res[i] > res[i-1]:
pass
else:
sum += res[-1]
return sum
print(calc(res))
For some reason, the program does not count. According to the idea, it should take the values of Roman numerals, translate them using a dictionary into Arabic (for example, it takes X, translates to 10), that is, in the toga we have an array consisting of Arabic numerals, after which we count according to the algorithm (for example, IX, compare the digits if I is less than X (1 is less than 10), then we count 10-1), but for some reason the program does not work correctly
Code:
BASE = { "I":1, "V":5, "X":10, "L":50, "C":100, "M":1000 }
value_ = tuple(input('Введите римскую цифру: '))
def perevod(value): for value in value: x = [] arab_value = x.append(BASE[value]) print(x) return arab_value
sum = 0
def value(arab_value): for value in arab_value: i = 0 if value[i] >= value[i+1]: sum += value[i]
else: sum += values[i+1] - values[i] i += 1 return value
print (f'Ваше число = {sum}')