Skip to content

Commit 70999c5

Browse files
authored
Merge pull request #3 from Shuchi2211/Shuchi2211-patch-3
Create rom_to_dec.py
2 parents c0e1903 + 4944c51 commit 70999c5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: Basic Scripts/rom_to_dec.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
tallies = {
3+
'I': 1,
4+
'V': 5,
5+
'X': 10,
6+
'L': 50,
7+
'C': 100,
8+
'D': 500,
9+
'M': 1000,
10+
# specify more numerals if you wish
11+
}
12+
13+
def RomanNumeralToDecimal(romanNumeral):
14+
sum = 0
15+
for i in range(len(romanNumeral) - 1):
16+
left = romanNumeral[i]
17+
right = romanNumeral[i + 1]
18+
if tallies[left] < tallies[right]:
19+
sum -= tallies[left]
20+
else:
21+
sum += tallies[left]
22+
sum += tallies[romanNumeral[-1]]
23+
return sum

0 commit comments

Comments
 (0)