Count Non-Positive Numbers
EasyPractice library · +10 XPbasicsloopsconditionals
Given a list of N integers, count how many of them are non-positive (i.e., less than or equal to 0). Print this count.
Input
The first line contains an integer N (1 <= N <= 1000). The second line contains N space-separated integers.
Output
Print a single integer: the count of non-positive numbers.
Constraints
1 <= N <= 1000 Each integer is between -10^9 and 10^9.
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
5 1 -2 0 3 -4
Output
3
There are 3 non-positive numbers: -2, 0, and -4.
Example 2
Input
3 10 20 30
Output
0
There are 0 non-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 0 3 -4
Example 2 input
3 10 20 30