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

Lab 5 - Find/count number of positive values in array

def find_count_pos(a):
    n = a
    i = 0
    suma = 0
    x = 0     #amount of positve numer
    while(i < len(n)):
        if(n[i] > 0):
            suma = suma + n[ i ]
            print("Index of Positive number = n[", i ,"]")
            x = x + 1
        i = i + 1        
    print("Summary of Positive number is =", suma)
    print("Amount of Positive number is =", x)
   
find_count_pos([-5, 4, 3, 2, 1, -6, -3])


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

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