Saturday, September 26, 2015

Lab5 - Find/count number of positive values in array

def count_pos(n):
    i=0
    count=0
    while(i<len(n)):
        if(n[i]>0):
            count+=1
            print("n[",i,"]","is",n[i])
        i+=1
    return count
   
def setup():
     n=[5,8,-9,7,5,3,-2,9]
     print("Number of positive values in array",count_pos(n))
    
setup()

No comments:

Post a Comment