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
Inicia sesión para ver tu historial de envíos
Iniciar sesiónInicia sesión para usar el AI Mentor
Iniciar sesiónTests12
Visible tests
Prueba oculta 7
Prueba oculta 8
Prueba oculta 9
Prueba oculta 10
Prueba oculta 11
Prueba oculta 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