Python Program to Count Only Positive And Negative Number Of A List

Example

def checkPositiveNegative(data,length):
    
    for i in range(length):
        if data[i] > 0:
            positiveArray.append(data[i])
        elif data[i] < 0:
            negativeArray.append(data[i])
            
    print('Total positive values are: ',len(positiveArray))
    print('Total negative values are: ',len(negativeArray))
    print('Total number of zeros are: ',(length - len(positiveArray) - len(negativeArray)))
    
    
list01 = [-41, 0, 34, 10, -32, 0, 50, 21, -45, -67, 28]
length=len(list01)

positiveArray=[]
negativeArray=[]

checkPositiveNegative(list01,length)

Output:

Total positive values are:  5
Total negative values are:  4
Total number of zeros are:  2

Leave a comment