{"base":{"id":"cs9-08","subject":"Programming","title":"Arrays and indexes","scene":"py9","steps":[{"mode":"array","eyebrow":"Index","title":"Pick one item","body":"An array stores a set of related values under one name. Each item has an index, starting at 0. Move the slider to read different items.","controls":[{"id":"i","label":"Index","min":0,"max":4,"step":1,"value":2}]},{"mode":"arrloop","eyebrow":"Loop over an array","title":"Visit every item","body":"A loop with an index can visit every item. Here it adds all the scores. Step through and watch i and total.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"mode":"whyarray","eyebrow":"Why arrays?","title":"One name instead of many","body":"Compare five separate variables with one array. Which is easier to loop over and extend?"},{"mode":"quiz","eyebrow":"Check yourself","title":"Index","body":"colours = [\"red\", \"green\", \"blue\", \"pink\"]","question":"What is colours[2]?","options":["\"green\"","\"blue\"","\"pink\""],"answer":1,"right":"Correct. Indexes start at 0: red is 0, green 1, blue 2.","wrong":"Not quite. Count from 0.","look":"array"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"The first item has index 1.\"","body":"In Python (and most languages) the first index is 0."},{"tag":"Popular idea","title":"\"An array can only hold numbers.\"","body":"It can hold strings, Booleans and more."},{"tag":"Popular idea","title":"\"scores[5] works for a 5-item list.\"","body":"The last index is 4; scores[5] causes an IndexError."}]},{"type":"cards","id":"code","eyebrow":"Python","title":"Using arrays","items":[{"tag":"Read","title":"By index","body":"names = [\"Ava\", \"Leo\", \"Mia\"]\nprint(names[0])   # Ava","code":true},{"tag":"Loop","title":"Every item","body":"for i in range(len(names)):\n    print(i, names[i])","code":true},{"tag":"Change","title":"Add and update","body":"names.append(\"Omar\")\nnames[1] = \"Kai\"","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Egg-box array","items":[{"title":"A physical array","time":"15 minutes","need":["An egg box or 6 cups","Small paper notes"],"steps":["Label the spaces 0 to 5.","Put a word in each space on a note.","A partner calls an index; you read out the word.","What happens if they call 6?"],"why":"Arrays store items in numbered positions, starting at 0.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"In [4, 8, 15, 16], what is at index 0?","options":["4","8","Nothing"],"answer":0,"right":"Correct. The first item.","wrong":"Not quite. Index 0 is first."},{"question":"How many items in a list with indexes 0 to 9?","options":["9","11","10"],"answer":2,"right":"Correct. 0 to 9 is 10 positions.","wrong":"Not quite. Count them."},{"question":"What does len([3, 6, 9]) return?","options":["9","2","3"],"answer":2,"right":"Correct. Three items.","wrong":"Not quite. len counts items."},{"question":"nums = [5, 10, 15]. nums[1] = 99. nums is now…","options":["[5, 99, 15]","[99, 10, 15]","[5, 10, 99]"],"answer":0,"right":"Correct. Index 1 is the second item.","wrong":"Not quite. Which position is 1?"},{"question":"Why store 30 test scores in an array?","options":["It uses no memory","One name, easy to loop over","Variables can't hold numbers"],"answer":1,"right":"Correct. Loops can process them all.","wrong":"Not quite. Think of 30 variable names."},{"question":"Which loop visits every item of scores?","options":["for i in range(1, len(scores))","for i in range(len(scores))","for i in range(len(scores) + 1)"],"answer":1,"right":"Correct. Indexes 0 to len − 1.","wrong":"Not quite. Start at 0, stop before len."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["why one array is easier than many variables","how indexes start at 0","how to read an item by its index","how to loop through an array"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"array","meaning":"A collection of values stored under one name."},{"word":"index","meaning":"The position number of an item, starting at 0."},{"word":"element","meaning":"One item in an array."},{"word":"list","meaning":"Python's name for an array."},{"word":"len","meaning":"A function giving the number of items."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize KS3 Computer Science","Raspberry Pi Foundation, Computing curriculum resources"]}]},"overlay":null}