From e6ea0ba222ac2fba1a7a83c53caf43da33ff1d63 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:53:57 +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 | 43 +++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/conversions/roman_numerals.py b/conversions/roman_numerals.py index eba367142..24183ea4d 100644 --- a/conversions/roman_numerals.py +++ b/conversions/roman_numerals.py @@ -1,11 +1,32 @@ ROMAN = [ -(1000000, "M_"), (900000, "C_M_"), (500000, "D_"), (400000, "C_D_"), - (100000, "C_"), (90000, "X_C_"), (50000, "L_"), (40000, "X_L_"), - (10000, "X_"), (9000, "I_X_"), (5000, "V_"), (4000, "I_V_"), - (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), - (100, "C"), (90, "XC"), (50, "L"), (40, "XL"), - (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I") + (1000000, "M_"), + (900000, "C_M_"), + (500000, "D_"), + (400000, "C_D_"), + (100000, "C_"), + (90000, "X_C_"), + (50000, "L_"), + (40000, "X_L_"), + (10000, "X_"), + (9000, "I_X_"), + (5000, "V_"), + (4000, "I_V_"), + (1000, "M"), + (900, "CM"), + (500, "D"), + (400, "CD"), + (100, "C"), + (90, "XC"), + (50, "L"), + (40, "XL"), + (10, "X"), + (9, "IX"), + (5, "V"), + (4, "IV"), + (1, "I"), ] + + def roman_to_int(roman): """ Convert a Roman numeral to an integer, supporting Vinculum notation @@ -26,13 +47,15 @@ def roman_to_int(roman): i, total = 0, 0 while i < len(roman): - 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): """ Convert an integer to a Roman numeral, supporting Vinculum notation @@ -55,7 +78,9 @@ def int_to_roman(number): if number == 0: break return "".join(result) - + + if __name__ == "__main__": import doctest + doctest.testmod()