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
Συνδεθείτε για να δείτε το ιστορικό υποβολών
ΣύνδεσηΣυνδεθείτε για να χρησιμοποιήσετε τον AI Mentor
ΣύνδεσηTests12
Visible tests
Κρυφό τεστ 7
Κρυφό τεστ 8
Κρυφό τεστ 9
Κρυφό τεστ 10
Κρυφό τεστ 11
Κρυφό τεστ 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