Count the positives
Inputs
values is a list of 0 to 14 whole numbers, each from -20 to 20.
Your tasks
- Create a number
countthat starts at 0. - Use a loop over
values. Add 1 tocountfor each number that is greater than 0. - Complete
countPositivesso it returnscount. Return it, do not print it.
Example
With values = [3, -1, 0, 8, -5, 2], countPositives returns 3.
Rules
- Zero is not positive.
Test data
TEST DATA 1: values is [3, -1, 0, 8, -5, 2]
TEST DATA 2: values is []
Practice focus
One pass over a list to add, count, find the biggest and the smallest. Scanning an array once and keeping a running answer is the backbone of linear-time solutions.