美文网首页
Sum of positive

Sum of positive

作者: 是不及呀 | 来源:发表于2018-11-29 13:24 被阅读0次
* *
链接 Sum of positive
难度 8kyu
状态
日期 2018-11-30

题意

题解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])

相关文章

网友评论

      本文标题:Sum of positive

      本文链接:https://www.haomeiwen.com/subject/dfzxcqtx.html