Practice using arrays and lists to store ordered values, access elements by index, update data, and reason about common algorithms.
Read each problem carefully. Show your work in the space provided. Assume indexes start at 0 unless the problem says otherwise.
Storing, accessing, and updating ordered data
CS - Grade 9-12
- 1
A list named scores stores the values [88, 92, 75, 100, 67]. What value is stored at index 2? Explain how you found it.
- 2
A list named colors starts as ["red", "blue", "green", "yellow"]. After the statement colors[1] = "purple", what is the list?
- 3
A program has the list nums = [4, 8, 15, 16, 23, 42]. Write the value of nums[0] + nums[5] and explain your answer.
- 4
A list named names contains 6 elements. What are the valid index values for this list if the language uses 0-based indexing?
- 5
Explain the difference between an array and a list in many programming languages. Include one example of when a list may be easier to use.
- 6
A list starts as [10, 20, 30]. A program appends 40 to the list. What is the list after the append operation?
- 7
A list named letters starts as ["a", "b", "c", "d"]. A program removes the element at index 2. What is the list after the removal?
- 8
Trace this loop and write the final value of total: nums = [3, 5, 2, 10]; total = 0; for each n in nums: total = total + n.
- 9
Write pseudocode that prints every element in the list temperatures = [72, 68, 75, 70].
- 10
A list named values is [9, 1, 6, 3]. Write pseudocode to find the largest value in the list.
- 11
A program tries to access items[10] when items has length 10. Explain the error.
- 12
A list of test scores is [80, 95, 70, 100, 85]. Write pseudocode to count how many scores are at least 90.