mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-23 09:38:27 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
6bff12142e
commit
dd13fe23b0
@ -25,6 +25,8 @@ ROMAN = [
|
|||||||
(4, "IV"),
|
(4, "IV"),
|
||||||
(1, "I"),
|
(1, "I"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def roman_to_int(roman: str) -> int:
|
def roman_to_int(roman: str) -> int:
|
||||||
"""
|
"""
|
||||||
Convert a Roman numeral to an integer, supporting Vinculum notation
|
Convert a Roman numeral to an integer, supporting Vinculum notation
|
||||||
@ -45,13 +47,15 @@ def roman_to_int(roman: str) -> int:
|
|||||||
i, total = 0, 0
|
i, total = 0, 0
|
||||||
while i < len(roman):
|
while i < len(roman):
|
||||||
# Check for 2-character symbols first (like I_ or X_)
|
# Check for 2-character symbols first (like I_ or X_)
|
||||||
if i + 1 < len(roman) and roman[i:i+2] in vals:
|
if i + 1 < len(roman) and roman[i : i + 2] in vals:
|
||||||
total += vals[roman[i:i+2]]
|
total += vals[roman[i : i + 2]]
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
total += vals[roman[i]]
|
total += vals[roman[i]]
|
||||||
i += 1
|
i += 1
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
|
||||||
def int_to_roman(number: int) -> str:
|
def int_to_roman(number: int) -> str:
|
||||||
"""
|
"""
|
||||||
Convert an integer to a Roman numeral, supporting Vinculum notation
|
Convert an integer to a Roman numeral, supporting Vinculum notation
|
||||||
@ -75,6 +79,8 @@ def int_to_roman(number: int) -> str:
|
|||||||
break
|
break
|
||||||
return "".join(result)
|
return "".join(result)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user