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
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachTests12
Visible tests
Tástáil fholaithe 7
Tástáil fholaithe 8
Tástáil fholaithe 9
Tástáil fholaithe 10
Tástáil fholaithe 11
Tástáil fholaithe 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid