Skip to content

Commit c87c3fc

Browse files
authored
Merge branch 'DeepNinja07x:master' into master
2 parents 6e55a70 + 0b1b297 commit c87c3fc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Basic Scripts/roman_to_dec.py

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

0 commit comments

Comments
 (0)