Count Good, Sum Bad
In a list of numbers, you may want to measure positive and negative values separately. Write count_positives_sum_negatives, which returns a two-element list: the count of positive numbers and the sum of negative numbers. Zero is neither positive nor negative, and if the input list is empty, return an empty list.
Примеры
Ввод
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]Вывод
[10, -65]Ввод
[0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14]Вывод
[8, -50]Ввод
[]Вывод
[]Нужно реализовать
def count_positives_sum_negatives(arr: list[int]) -> list[int]:
Теги
listsarraymath
Prisijunkite, kad matytumėte pateikimų istoriją
PrisijungtiPrisijunkite, kad naudotumėte DI mentorių
PrisijungtiVisible tests
1
Input
[1,2,3,4,5,6,7,8,9,10,-11,-12,-13,-14,-15]Expected
[10,-65]2
Input
[0,2,3,0,5,6,7,8,9,10,-11,-12,-13,-14]Expected
[8,-50]3
Input
[]Expected
[]4
Input
[-1,-2,-3]Expected
[0,-6]5
Input
[1,2,3]Expected
[3,0]6
Input
[10,9,8,7,6,5,4,3,2,1,-11,-12,-13,-14,-15]Expected
[10,-65]Focus radio
Paused · SomaFM · Fluid