Index Power 0 / 30
Index Rank Index Fumbler

Topic 2.2.9: Arrays & Data Structures

1D & 2D Arrays, Logic & Iteration.

1 [2 Marks]
total = 0 for i = 0 to ......................... - 1 total = total + scores[.........................] next i print(total)
Fill blanks (calculate total of scores).
✅ Mark Scheme
  • scores.length (or 5)
  • i
Score:
2 [2 Marks]
Two benefits of using an Array instead of separate variables?
✅ Mark Scheme

Efficient coding (using loops), Easier to sort/search, Easier maintenance.

Score:
3 [4 Marks]
Rows 0-1, Cols 0-2.
(a) Data at [1, 0]?
(b) Data at [0, 2]?
(c) Result of [2, 0]?
✅ Mark Scheme

(a) "Dan"

(b) "Caz"

(c) Error / Out of bounds. Row 2 does not exist.

Score:
4 [2 Marks]
# Col 1 is Price, Col 2 is Quantity stock[0, 1] = stock[0, 1] - 1
(a) Error?
(b) Fix?
✅ Mark Scheme

(a) Updates Price (Col 1) instead of Quantity (Col 2).

(b) stock[0, 2] = stock[0, 2] - 1

Score:
5 [4 Marks]
Grid: [[1, 2], [3, 4]]
If val > 2: total += val
Else: total -= 1
Final Total?
✅ Mark Scheme

Total: 5

(1 -> -1, 2 -> -1 total -2. 3 -> +3 total 1. 4 -> +4 total 5).

Score:
6 [2 Marks]
contacts = [07700900123, ...]
(a) Why missing zeros?
(b) Fix?
✅ Mark Scheme

(a) Stored as Integers (Integers don't have leading zeros).

(b) Store as Strings (Add quotes).

Score:
7 [6 Marks]
Ask for Student ID. Calculate Average of 3 tests from marks 2D array.
✅ Mark Scheme
id = int(input("Enter ID"))
total = 0
for i = 0 to 2
  total = total + marks[id, i]
next i
avg = total / 3
print(avg)
Score:
8 [6 Marks]
Search entire marks array for 100.
Print "Found" or "Not Found".
Hint: Don't print "Not Found" inside the loop!
✅ Mark Scheme
found = False
for r = 0 to 3
    for c = 0 to 2
        if marks[r, c] == 100 then
            found = True
            print("Found")
        endif
    next c
next r
if found == False then print("Not Found")
Score: