Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'devel' into new-func
Browse files Browse the repository at this point in the history
  • Loading branch information
shorodilov authored Jan 3, 2024
2 parents a19dbde + c3d1252 commit 1be229f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/calc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

__all__ = [
"get_digits_multiplies",
"get_factorial",
"get_fibonacci_number",
"get_fibonacci_number_nr",
Expand All @@ -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)
15 changes: 15 additions & 0 deletions src/calc/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
7 changes: 7 additions & 0 deletions tests/calc/func_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 1be229f

Please sign in to comment.