File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 25
25
(4 , "IV" ),
26
26
(1 , "I" ),
27
27
]
28
+
29
+
28
30
def roman_to_int (roman : str ) -> int :
29
31
"""
30
32
Convert a Roman numeral to an integer, supporting Vinculum notation
@@ -45,13 +47,15 @@ def roman_to_int(roman: str) -> int:
45
47
i , total = 0 , 0
46
48
while i < len (roman ):
47
49
# Check for 2-character symbols first (like I_ or X_)
48
- if i + 1 < len (roman ) and roman [i : i + 2 ] in vals :
49
- total += vals [roman [i : i + 2 ]]
50
+ if i + 1 < len (roman ) and roman [i : i + 2 ] in vals :
51
+ total += vals [roman [i : i + 2 ]]
50
52
i += 2
51
53
else :
52
54
total += vals [roman [i ]]
53
55
i += 1
54
56
return total
57
+
58
+
55
59
def int_to_roman (number : int ) -> str :
56
60
"""
57
61
Convert an integer to a Roman numeral, supporting Vinculum notation
@@ -74,7 +78,9 @@ def int_to_roman(number: int) -> str:
74
78
if number == 0 :
75
79
break
76
80
return "" .join (result )
77
-
81
+
82
+
78
83
if __name__ == "__main__" :
79
84
import doctest
85
+
80
86
doctest .testmod ()
You can’t perform that action at this time.
0 commit comments