A programmer wrote the program below. The program uses a list of numbers called numList. The
program is intended to display the sum of the numbers in the list.
In order to test the program, the programmer initializes numList to [0, 1, 4, 5].
The program displays 10, and the programmer concludes than the program works as intended. Which of the following is true?
Approach
The main issue with the program is that sum is initialize with the value equal to the first item in numList.
If this value is 0, like in the scenario given, the program works correctly in adding the values. However, if the first value is not 0, the sum will not be correct.
For example, if we run [5, 1, 2]through the program, the sum will be 13 instead of 8.