Year 11 Computing — Changing and growing a list
Work out what a list holds after values have been added on the end, written over, or joined on from another list.
Name: ________________________
1.A list called pins holds [8, 3]. Each of these lines is run on its own, starting from that list every time. Put them in order of how many values pins holds afterwards, fewest first.
- pins.append(9)
- pins[0] = 4
- pins = pins + [6, 7, 0]
- pins = pins + [1, 2]
2.Two values are added on the end, one after the other. What does this program print?
bag = [3] bag.append(7) bag.append(2) print(bag[1] + bag[2])
3.A value is written over, and then the list is measured. What does this program print?
sizes = [5, 2, 9] sizes[0] = 40 print(len(sizes))
4.Two lists are joined into a third one here. What does this program print?
first = [1, 2] second = [7, 8, 9] both = first + second print(len(both))
5.Something is added on the end and something else is written over. What does this program print?
row = [2, 4, 6] row.append(8) row[0] = 10 print(row[0] + row[3])
6.Something is added on the end, and then a position from before the change is asked for. What does the program print?
marks = [12, 7, 20] marks.append(5) print(marks[2])
7.Two lists are joined, and then a position is asked for out of the joined one. What does this program print?
a = [10, 20] b = [30, 40, 50] c = a + b print(c[3])
8.A list called box already holds four values. Sort each line by what it does to how long the list is.
Groups: Makes the list longer · Leaves the length alone
- box[0] = 7
- box.append(0)
- box.append(7)
- box.append(12)
- box[3] = 1
- box[2] = 9
Answer key — Year 11 Computing — Changing and growing a list
- 1. 1. pins[0] = 4 2. pins.append(9) 3. pins = pins + [1, 2] 4. pins = pins + [6, 7, 0]
- 2. 9
- 3. 3
- 4. 5
- 5. 18
- 6. 20
- 7. 40
- 8. box.append(7) → Makes the list longer; box[0] = 7 → Leaves the length alone; box.append(0) → Makes the list longer; box[3] = 1 → Leaves the length alone; box.append(12) → Makes the list longer; box[2] = 9 → Leaves the length alone