나는 이렇게 학습한다/Algorithm & SQL

0929. Summing a number's digits

daco2020 2022. 9. 29. 21:56
반응형

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)) 

 

 

반응형