반응형
Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits.
For example: (Input --> Output)
10 --> 1 99 --> 18 -32 --> 5
Let's assume that all numbers in the input will be integer values.
Solution:
def get_str_number(func): def wrapper(number): return func(str(number).replace("-", "")) return wrapper @get_str_number def sum_digits(number: str): return sum(map(int, number))
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1001. Hello, Name or World! (0) | 2022.10.02 |
---|---|
0930. Count of positives, sum of negatives (0) | 2022.09.30 |
0928. Grasshopper - Terminal game combat function (0) | 2022.09.28 |
0927. Opposites Attract (0) | 2022.09.27 |
0926. Merge two sorted arrays into one (0) | 2022.09.26 |