 # roman numerals to Arabic numerals(Only X V I)

Jul 30th, 2021 (edited)
138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def main(roman_number: str) -> int:
2.
3.     next = 0 #next count
4.     result = 0 #it is our future result
5.     arab_number = {  #this is roman numerals to Arabic numerals vocablurary
6.     'x':10,
7.     'v':5,
8.     'i':1
9.     }
10.     rnm = [] #rnm is Roman_number_massive
11.     roman_number = roman_number.lower()
12.
13.     for i in range(0, len(roman_number)):
14.         rnm.append(arab_number.get(roman_number[i])) #str to massive
15.     pn = len(rnm) #index of the next count
16.     prev = rnm #previous count
17.     for i in range(0, len(rnm)):
18.         if rnm[i] >= prev and pn!=i: #pn!=i it is index of next count is not current index
19.             if len(rnm)==2 and prev<rnm[i]:
20.                 result= rnm[i]-prev
21.             else:
22.                 result+= rnm[i]
23.                 prev = rnm[i]
24.         elif rnm[i]<prev and pn!=i:
25.             pn = i+1
26.             if i+1 < len(rnm):
27.                 next = rnm[i+1]
28.                 prev = next
29.                 if next<rnm[i]:
30.                     result += (rnm[i]+next)
31.                 elif next>rnm[i]:
32.                     result += (next-rnm[i])
33.                 elif next==rnm[i]:
34.                     result+= rnm[i]+next
35.             elif i+1 == len(rnm):
36.                 result+=rnm[i]
37.         elif rnm[i]<prev:
38.             result+=rnm[i]-prev
39.         elif pn == i:
40.             pass
41.     return(result)
RAW Paste Data