반응형
Write a function that takes an array of numbers and returns the sum of the numbers. The numbers can be negative or non-integer. If the array does not contain any numbers then you should return 0.
Examples Input: [1, 5.2, 4, 0, -1] Output: 9.2
Input: [] Output: 0
Input: [-2.398] Output: -2.398
Assumptions You can assume that you are only given numbers. You cannot assume the size of the array. You can assume that you do get an array and if the array is empty, return 0.
Solution:
def sum_arr(func):
def wrapper(*args):
return func(sum(*args))
return wrapper
@sum_arr
def sum_array(value):
return value
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0829. Holiday VIII - Duty Free (0) | 2022.08.29 |
---|---|
0828. Basic Mathematical Operations (0) | 2022.08.28 |
0826. A wolf in sheep's clothing (0) | 2022.08.26 |
0825. Find the first non-consecutive number (0) | 2022.08.25 |
0824. N-th Power (0) | 2022.08.24 |