Part of the series

Several example codes

~1 min read • Updated Sep 24, 2025

Program Overview

This Python program receives a list of numbers and counts how many of them are positive.
Positive numbers are defined as values greater than zero.


Python Code:


# Sample list of numbers
numbers = [-5, 0, 12, 7, -3, 9, 0, 4]

# Count how many numbers are positive
positive_count = len([num for num in numbers if num > 0])

# Display the result
print("Number of positive values:", positive_count)

Sample Output:


Number of positive values: 4

Explanation:

- The list numbers contains a mix of positive, negative, and zero values
- A list comprehension filters out values greater than zero
- The len() function counts how many items are in the filtered list
- The result is printed using print()


Written & researched by Dr. Shahin Siami