{"base":{"id":"cs10-23","subject":"Programming","title":"Arrays: 1D and 2D","scene":"mix","steps":[{"use":"py9","mode":"whyarray","eyebrow":"Why arrays?","title":"One name instead of many","body":"An array stores many values of the same type under one name. Each item has an index."},{"use":"py9","mode":"array","eyebrow":"Indexing","title":"Pick one item","body":"Use an index to read one item. Move the index.","controls":[{"id":"i","label":"Index","min":0,"max":4,"step":1,"value":2}]},{"use":"py9","mode":"arrloop","eyebrow":"Looping through an array","title":"Visit every item","body":"A FOR loop with the index as its counter visits every element. Step through.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"cs10t3","mode":"array2d","eyebrow":"2D arrays","title":"Rows and columns","body":"A 2D array is a table. scores[row, col] picks one cell. Move the sliders, then show row totals with nested loops.","controls":[{"id":"r","label":"Row","min":0,"max":3,"step":1,"value":1},{"id":"c","label":"Column","min":0,"max":3,"step":1,"value":2}],"actions":[{"id":"rows","label":"Row totals"}]},{"use":"cs10t3","mode":"quiz","look":"array2d","eyebrow":"Check yourself","title":"2D index","body":"scores[2, 0] in the table: row 2 is Chidi, column 0 is T1.","question":"What value is stored there?","options":["9","20","12"],"answer":1,"right":"Correct. Row 2, column 0 is 20.","wrong":"Not quite. Row first, then column; both start at 0."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"Declare","title":"Pseudocode","body":"DECLARE temps : ARRAY[0:6] OF REAL\ntemps[0] ← 21.5","code":true},{"tag":"Total","title":"Loop","body":"total ← 0\nFOR i ← 0 TO 6\n  total ← total + temps[i]\nNEXT i\naverage ← total / 7","code":true},{"tag":"Python","title":"List","body":"temps = [21.5, 23.0, 19.8]\nfor t in temps:\n    print(t)\nprint(max(temps))","code":true},{"tag":"2D","title":"Python","body":"grid = [[0]*3 for _ in range(3)]\ngrid[1][2] = 5      # row 1, column 2","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Index out of range","body":"An array of 5 items has indexes 0–4. Accessing [5] crashes."},{"tag":"Mistake","title":"Swapping row and column","body":"Always row first, then column (or as your course defines)."},{"tag":"Mistake","title":"Loop bounds off by one","body":"FOR i ← 0 TO LENGTH − 1, not TO LENGTH."},{"tag":"Mistake","title":"Mixing types","body":"In a strict array, every element has the same data type."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"How it works","title":"Memory addresses","body":"An array sits in a block of memory. The address of item i is start + i × size, so any item can be reached in one step. That's why indexing is fast."},{"tag":"Real world","title":"Images are 2D arrays","body":"A photo is a 2D array of pixels; each pixel stores colour values. A 12-megapixel photo is a table of about 4000 × 3000 entries."},{"tag":"Going further","title":"Spreadsheets","body":"A spreadsheet is a giant 2D array with formulas. B3 is just row 3, column B."}]},{"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":"Code","body":"Write pseudocode to find the largest value in an array of 10 numbers.\n\nAnswer:\nmax ← nums[0]\nFOR i ← 1 TO 9\n  IF nums[i] > max THEN max ← nums[i]\nNEXT i","code":true},{"tag":"Challenge","title":"2D","body":"How many elements in an ARRAY[0:4, 0:9]?\n\nAnswer: 5 × 10 = 50."},{"tag":"Challenge","title":"Trace","body":"nums = [3, 8, 1]. After nums[1] = nums[0] + nums[2], what is nums?\n\nAnswer: [3, 4, 1]."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Egg-box array","time":"10 minutes","need":["An empty egg box (or a grid drawn on paper)","Small objects such as coins"],"steps":["Number the cups as a 2 × 6 array: rows 0–1, columns 0–5.","Ask someone to name a position like [1, 3] and place a coin there.","Write the pseudocode to count coins in row 0."],"why":"You modelled a 2D array and nested-loop counting.","safety":"None."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"An array of 8 items has last index…","options":["8","9","7"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"names[0] gives…","options":["the first item","the last item","the length"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"A 2D array needs how many indexes?","options":["1","2","3"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"To visit every item we usually use…","options":["an IF","a CASE","a FOR loop"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Arrays store items of…","options":["the same type","any type mixed","only strings"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Total of [2, 4, 6] =","options":["6","12","3"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"grid[2][0] in Python means…","options":["column 2, row 0","the third grid","row 2, column 0"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Visiting every cell of a 2D array uses…","options":["nested loops","one IF","recursion only"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["explain why arrays are useful","declare and index 1D arrays","loop through an array to total, average and find max/min","declare and index 2D arrays","use nested loops with 2D arrays","avoid index-out-of-range errors"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"Array","meaning":"A data structure holding many values of one type under one name."},{"word":"Element","meaning":"One item in an array."},{"word":"Index","meaning":"The position number of an element."},{"word":"2D array","meaning":"An array with rows and columns."},{"word":"Nested loop","meaning":"A loop inside another loop."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: Lists","Raspberry Pi Foundation, Isaac Computer Science: arrays","BBC Bitesize, GCSE Computer Science: arrays","Khan Academy: arrays in programming"]}]},"overlay":null}