Count Positive, Negative, Zero

Count positive, negative, and zero elements.

Logic BuildingBeginner
Logic Building
# Take array
n = int(input("Enter array size: "))
arr = []
for i in range(n):
    arr.append(int(input(f"Element {i+1}: ")))

# Count
positive = 0
negative = 0
zero = 0

for element in arr:
    if element > 0:
        positive += 1
    elif element < 0:
        negative += 1
    else:
        zero += 1

print(f"Positive: {positive}, Negative: {negative}, Zero: {zero}")

Output

Enter array size: 5
Element 1: 5
Element 2: -3
Element 3: 0
Element 4: 10
Element 5: -2
Positive: 2, Negative: 2, Zero: 1

Classify each element and count.

Key Concepts:

  • Check if > 0, < 0, or == 0
  • Increment respective counter
  • Print all counts