Problem A
Count Negative
If you are doing this problem outside of a class, or your instructor has not given you code to use as a starting point, skip ahead to the Input/Output sections for a concise description of the input/output requirements of this problem.
CS 121 students: To solve this problem, use file countnegative.py from your CS 121 repository as a starting point. It will handle the input/output, and all you will need to do is add code in the places indicated in the file.
You must implement a function called count_negative that, given a list of integers, must return the number of negative integers in that list.
If you are using countnegative.py as a starting point, you can ignore the rest of the Input/Output sections below. Just submit your modified countnegative.py once you have written your solution.
Input
The input is composed of one or two lines. The first line contains an integer $n$ ($0 \le n \le 100$) that specifies the number of values in the list. If $n=0$, there is no second line (i.e., the input is an empty list of values). If $n>0$, then the second line contains the $n$ integers (for each integer $x$, $-1\, 000\, 000 \leqslant x \leqslant 1\, 000\, 000$), each separated by a single space.
Output
You must print a single integer: the number of negative values in the input.
Sample Input 1 | Sample Output 1 |
---|---|
3 5 -10 15 |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
5 -14 -5 -39 -5 -7 |
5 |
Sample Input 3 | Sample Output 3 |
---|---|
0 |
0 |