Ready to begin
No records have been processed. Start with Next step.
Create chemMarks={}, then scan each score card. Store chemMarks[X.CardNo]=X.Chemistry. The lecture shows names as keys; the lab uses unique CardNo values so that repeated names would not overwrite another student. The dictionary keeps a computed view without altering the source cards.
Follow the dictionary as its keys and values change. Predict each lookup or update before revealing the next step.
Ready
No records have been processed. Start with Next step.
Predict the next key, whether it already exists, and the value that will be stored.

Follow the dictionary as its keys and values change. Predict each lookup or update before revealing the next step.
Ready
No records have been processed. Start with Next step.
Predict the next key, whether it already exists, and the value that will be stored.
chemMarks = {}
while (Table 1 has more rows) {
Read the first row X in Table 1
chemMarks[X.CardNo] = X.Chemistry
Move X to Table 2
}
total = 0
count = 0
foreach k in keys(chemMarks) {
total = total + chemMarks[k]
count = count + 1
}
if (count > 0) {
average = total / count
}For the original 30 cards, Chemistry totals 2314 and the mean is 2314/30 ≈ 77.1333. Switching the lab field recomputes the values from those same cards. An empty input has no average; report it rather than dividing by zero.
Should the average add keys 0,1,2,…?
No. Add the marks stored at those keys.
Why use a count variable as well as a total?
The total is divided by the number of student entries processed.
What does overwriting duplicate name keys do to an average?
It can remove a student’s earlier mark from the dictionary, making the resulting average differ from the full-record average.