วันพุธที่ 23 กันยายน พ.ศ. 2558

Lab 5 - Find sum of positive values in array

def pos_sum(a):
    n = a
    i = 0
    suma = 0
    while(i < len(n)):
        if(n[i] > 0):
            suma = suma + n[ i ]
        i = i + 1        
    print("Summary of Positive number is =", suma)
   
pos_sum([-5, 4, 3, 2, 1, -6, -3])


ไม่มีความคิดเห็น:

แสดงความคิดเห็น