Count Positive Numbers
EasyPractice library · +10 XPbasicsloopsconditional
Given a list of N integers, count how many of them are strictly positive. A number is strictly positive if it is greater than 0.
Input
The first line contains a single integer N, the number of integers in the list. The second line contains N space-separated integers.
Output
Print a single integer: the count of strictly positive numbers in the list.
Constraints
1 <= N <= 1000 -1000 <= A[i] <= 1000, where A[i] is the i-th integer.
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
5 1 -2 3 0 5
Output
3
There are 3 positive numbers: 1, 3, and 5.
Example 2
Input
3 -1 -5 -10
Output
0
There are 0 positive numbers.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 1 -2 3 0 5
Example 2 input
3 -1 -5 -10