{"base":{"id":"cs11-04","subject":"Programming","title":"Two-dimensional arrays","scene":"mix","steps":[{"use":"cs10t3","mode":"array2d","eyebrow":"2D arrays","title":"Rows and columns","body":"A 2D array stores a table: scores[row, column]. Pick a cell.","controls":[{"id":"r","label":"Row","min":0,"max":3,"step":1,"value":2},{"id":"c","label":"Column","min":0,"max":3,"step":1,"value":1}]},{"use":"cs10t3","mode":"array2d","eyebrow":"Nested loops","title":"Visit every cell","body":"An outer loop for rows and an inner loop for columns visit every cell. Show the row totals.","controls":[{"id":"r","label":"Row","min":0,"max":3,"step":1,"value":0},{"id":"c","label":"Column","min":0,"max":3,"step":1,"value":0}],"actions":[{"id":"rows","label":"Row totals"}]},{"use":"py9","mode":"arrloop","eyebrow":"1D arrays recap","title":"Visit every item","body":"A 1D array is a single row.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"cs10t3","mode":"quiz","look":"array2d","eyebrow":"Check yourself","title":"Index","body":"grid is ARRAY[0:2, 0:4].","question":"How many elements does it hold?","options":["8","15","6"],"answer":1,"right":"Correct: 3 rows × 5 columns.","wrong":"Not quite."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"Declare","title":"Pseudocode","body":"DECLARE board : ARRAY[0:2, 0:2] OF CHAR\nboard[1, 1] ← \"X\"","code":true},{"tag":"Total","title":"Nested loop","body":"total ← 0\nFOR r ← 0 TO 3\n  FOR c ← 0 TO 3\n    total ← total + scores[r, c]\n  NEXT c\nNEXT r","code":true},{"tag":"Python","title":"List of lists","body":"grid = [[0] * 3 for _ in range(3)]\ngrid[2][0] = 5","code":true},{"tag":"Column total","title":"One column","body":"FOR r ← 0 TO 3: colTotal ← colTotal + scores[r, 2]","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Swapping indexes","body":"Keep row first, column second."},{"tag":"Mistake","title":"Inner loop resetting the outer counter","body":"Use different counter names."},{"tag":"Mistake","title":"Python [[0]*3]*3 trap","body":"This copies the same row three times; use a list comprehension."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"Games","title":"Boards","body":"Noughts and crosses, chess and puzzle games store their boards as 2D arrays."},{"tag":"Images","title":"Pixels","body":"Every digital image is a 2D array of colour values."}]},{"type":"cards","id":"challenge","eyebrow":"Challenge yourself","title":"Stretch your brain","intro":"Try each one on paper before opening the card.","items":[{"tag":"Challenge","title":"Write","body":"Find the highest score in a 4 × 4 array.\n\nAnswer:\nmax ← scores[0, 0]\nFOR r ← 0 TO 3\n  FOR c ← 0 TO 3\n    IF scores[r, c] > max THEN max ← scores[r, c]\n  NEXT c\nNEXT r","code":true},{"tag":"Challenge","title":"Count","body":"How many times does the inner statement run for a 5 × 8 array?\n\nAnswer: 40."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Noughts and crosses board","time":"30 minutes","need":["Python"],"steps":["Create a 3 × 3 list filled with \" \".","Let two players enter row and column.","Print the board after each move."],"why":"You use a real 2D array for a game.","safety":"None."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"A 2D array uses how many indexes?","options":["1","3","2"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"scores[2, 3] means…","options":["row 2, column 3","column 2, row 3","the 23rd item"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"ARRAY[0:3, 0:3] has…","options":["9 elements","16 elements","6 elements"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"To visit every cell use…","options":["one IF","a CASE","nested loops"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"In Python, grid[1][2] is…","options":["row 1, column 2","row 2, column 1","invalid"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Row totals need a total reset…","options":["only once","at the start of each row","never"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"A spreadsheet is like a…","options":["single variable","loop","2D array"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Index of the first row is usually…","options":["0","1","−1"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["declare and index 2D arrays","use nested loops for totals, max and search","calculate row and column totals","use 2D lists in Python"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"2D array","meaning":"A table of values with rows and columns."},{"word":"Row index","meaning":"Which row."},{"word":"Column index","meaning":"Which column."},{"word":"Nested loop","meaning":"A loop inside a loop."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: lists","Raspberry Pi Foundation, Isaac Computer Science: 2D arrays","BBC Bitesize, GCSE Computer Science: arrays","Python FAQ: multidimensional lists"]}]},"overlay":null}