easy +10 pts

Count Positives

Filter a list of numbers and return how many are greater than zero.

Write a function `count_positives(numbers)` that takes a list of integers (or floats) and returns the count of elements that are strictly greater than 0. The input list may be empty. Do not modify the input list. The function should return an integer.

Constraints

- The input list contains at most 10^4 elements. - Each element is an integer or a float. - The function should run in O(n) time and O(1) extra space.

Example

>>> count_positives([1, -2, 3, 0, -5])
2
>>> count_positives([0, 0, 0])
0
>>> count_positives([])
0
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Initialize a counter variable to 0.
Iterate over each number in the list.
Increment the counter when the number is greater than 0.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.