From c3d1252a46eaf917465c5b54eb6e43c39266a84b Mon Sep 17 00:00:00 2001 From: Serhii Horodilov Date: Tue, 19 Dec 2023 11:40:23 +0200 Subject: [PATCH] Implement get digits multipliers function (fixes GH-126) --- src/calc/__init__.py | 7 ++++--- src/calc/func.py | 15 +++++++++++++++ tests/calc/func_test.py | 7 +++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/calc/__init__.py b/src/calc/__init__.py index 923f925..0b35719 100644 --- a/src/calc/__init__.py +++ b/src/calc/__init__.py @@ -5,6 +5,7 @@ """ __all__ = [ + "get_digits_multiplies", "get_factorial", "get_fibonacci_number", "get_fibonacci_number_nr", @@ -13,6 +14,6 @@ "get_squares", ] -from calc.func import (get_factorial, get_fibonacci_number, - get_fibonacci_number_nr, get_square, get_squares, - get_sum_of_strings) +from calc.func import (get_digits_multiplies, get_factorial, + get_fibonacci_number, get_fibonacci_number_nr, + get_square, get_squares, get_sum_of_strings) diff --git a/src/calc/func.py b/src/calc/func.py index 3d86e57..d15f6c8 100644 --- a/src/calc/func.py +++ b/src/calc/func.py @@ -184,3 +184,18 @@ def get_sum_of_strings(number_1: str, number_2: str, /) -> str: result += str(carry) return result[::-1] + + +def get_digits_multiplies(origin: int) -> List[int]: + """ + Return the digits multiplies for a given number + + :param origin: a number to find multiplies + :type origin: int + + :return: a list of digits multiplies starting from position 10 ** 1 + :rtype: list + + """ + + return [int(digit) for digit in str(origin)[::-1]] diff --git a/tests/calc/func_test.py b/tests/calc/func_test.py index 7d2c57b..0fd23d5 100644 --- a/tests/calc/func_test.py +++ b/tests/calc/func_test.py @@ -66,3 +66,10 @@ def test_sum_of_strings_empty(): assert calc.get_sum_of_strings("123", "") == "123" assert calc.get_sum_of_strings("", "456") == "456" assert calc.get_sum_of_strings("", "") == "0" + + +def test_find_digits_multiplies(): + assert calc.get_digits_multiplies(123) == [3, 2, 1] + assert calc.get_digits_multiplies(456) == [6, 5, 4] + assert calc.get_digits_multiplies(0) == [0] + assert calc.get_digits_multiplies(2048) == [8, 4, 0, 2]