From dd13fe23b057b0df71c996fa5b466c3ecaae4bfb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2025 09:25:53 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conversions/roman_numerals.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/conversions/roman_numerals.py b/conversions/roman_numerals.py index da32198c4..548620c7a 100644 --- a/conversions/roman_numerals.py +++ b/conversions/roman_numerals.py @@ -25,6 +25,8 @@ ROMAN = [ (4, "IV"), (1, "I"), ] + + def roman_to_int(roman: str) -> int: """ 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 while i < len(roman): # Check for 2-character symbols first (like I_ or X_) - if i + 1 < len(roman) and roman[i:i+2] in vals: - total += vals[roman[i:i+2]] + if i + 1 < len(roman) and roman[i : i + 2] in vals: + total += vals[roman[i : i + 2]] i += 2 else: total += vals[roman[i]] i += 1 return total + + def int_to_roman(number: int) -> str: """ Convert an integer to a Roman numeral, supporting Vinculum notation @@ -74,7 +78,9 @@ def int_to_roman(number: int) -> str: if number == 0: break return "".join(result) - + + if __name__ == "__main__": import doctest + doctest.testmod()