-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path028.py
More file actions
28 lines (23 loc) · 640 Bytes
/
028.py
File metadata and controls
28 lines (23 loc) · 640 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# https://www.freecodecamp.org/learn/daily-coding-challenge/2025-09-07
symbols = {
"I": 1,
"V": 5,
"X": 10,
"L": 50,
"C": 100,
"D": 500,
"M": 1000,
}
def parse_roman_numeral(numeral):
return calculate_values(list(numeral), 0)
def calculate_values(numerals, value):
if len(numerals) == 0:
return value
if len(numerals) > 1 and symbols[numerals[0]] < symbols[numerals[1]]:
value += symbols[numerals[1]] - symbols[numerals[0]]
numerals.pop(1)
else:
value += symbols[numerals[0]]
numerals.pop(0)
value = calculate_values(numerals, value)
return value