Add the Positives
Sometimes you need to keep only the useful values from a list and ignore the negative ones. Write positive_sum, which takes a list of numbers arr and returns the sum of only the positive elements. If there are no positive numbers, return 0.
Примеры
Ввод
[1, 2, 3, 4, 5]Вывод
15Ввод
[1, -2, 3, 4, 5]Вывод
13Ввод
[-1, -2, -3, -4, -5]Вывод
0Нужно реализовать
def positive_sum(arr: list[int]) -> int:
Теги
listsarraymath
Logga in för att se historik över inskick
Logga inLogga in för att använda AI-mentorn
Logga inVisible tests
1
Input
[1,2,3,4,5]Expected
152
Input
[1,-2,3,4,5]Expected
133
Input
[-1,-2,-3,-4,-5]Expected
04
Input
[]Expected
05
Input
[1,-2,3,4,-5]Expected
86
Input
[-5,-2,1,3,4]Expected
8Focus radio
Paused · SomaFM · Fluid