Six marks, one box
Problem 3 needed three boxes for three subjects. Six subjects would need six boxes, and a class of two hundred students would need two hundred. That does not scale. A list holds many values in a single box, in a fixed order, and lets you reach any one of them by its position.
marks = [78, 65, 80]. The order you write them in is the order they stay in. A list can hold numbers, text, or anything else.marks[0].Counting starts at zero, not one. So the first item is
marks[0] and the third is marks[2]. This trips up nearly everybody at first, and it does not announce itself — asking for the wrong position gives you a real mark belonging to the wrong student.
Negative numbers count backwards from the end, so marks[-1] is the last item however long the list is.marks[0:3] hands back a smaller list. It starts at the first position and stops just before the second, so 0:3 gives you three items — positions 0, 1 and 2. The end is never included.Where the counting lands
| Position from the front | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| The mark there | 78 | 65 | 80 | 92 | 54 | 88 |
| Position from the back | -6 | -5 | -4 | -3 | -2 | -1 |
len(marks) counts the items. marks.append(70) adds one to the end — and unlike the string methods in problem 5, this one changes the list itself rather than handing back a new one. After appending, the list is longer and len reports a bigger number.What you are building
Build the programme
Your plan
The steps still to place
The whole programme is laid out below, in order. Five pieces are missing. Every one of them is a place where a small slip gives you a real-looking number belonging to the wrong student.
Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.
Run and read
Here is the whole programme. The list of marks is yours to change — type any marks separated by commas, or pick a suggestion. Watch what happens to the pieces that were pulled out by position.