题意
题解1
def positive_sum(arr):
# Your code here
sum = 0
len1 = len(arr)
a = 0
while a < len1:
if arr[a] > 0:
sum = sum + arr[a]
a = a + 1
else:
a = a + 1
return sum
题解2
def positive_sum(arr):
# Your code here
sum = 0
length = len(arr)
i = 0
while i < length:
if arr[i] > 0:
sum += arr[i]
i += 1
return sum
题解3
def positive_sum(arr):
# Your code here
sum = 0
length = len(arr)
for i in range(0, length):
if arr[i] > 0:
sum += arr[i]
return sum
题解4
def positive_sum(arr):
# Your code here
sum = 0
for n in arr:
if n > 0:
sum += n
return sum
题解5
def positive_sum(arr):
# Your code here
return sum([c for c in arr if c > 0])