{"base":{"id":"cs8-05","subject":"Algorithms","title":"Writing algorithms","scene":"code","steps":[{"mode":"vague","eyebrow":"Precise instructions","title":"Say exactly what you mean","body":"An algorithm is a set of precise steps that completes a task. A computer follows instructions exactly; it can't guess what you meant. Give the robot a vague instruction, then precise ones.","actions":[{"id":"vague","label":"“Go to the door.”"},{"id":"precise","label":"Precise steps"}]},{"mode":"sequence","eyebrow":"Start, finish, order","title":"Steps in the right order","body":"A good algorithm has a clear START and STOP, and its steps run in order: this is called sequence. Run the algorithm, then swap two lines and run it again.","actions":[{"id":"run","label":"Run the algorithm"},{"id":"swap","label":"Swap two lines"}]},{"mode":"variables","eyebrow":"Pseudocode","title":"Input, store, output","body":"Pseudocode is a clear way to write algorithms. INPUT gets a value, ← stores a value in a variable, OUTPUT shows it. Choose an age and step through line by line.","controls":[{"id":"age","label":"Value typed in for age","min":5,"max":17,"step":1,"value":12}],"actions":[{"id":"step","label":"Run one line"},{"id":"run","label":"Run it all"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Spot the precise step","body":"A robot must water a plant on a table 2 m in front of it.","question":"Which instruction is precise enough?","options":["Go and water it","Move forward 2 m, pour 200 ml","Water the plant soon"],"answer":1,"right":"Correct. It gives exact distances and amounts, so there is only one way to follow it.","wrong":"Not quite. Which one could only be followed in one way?"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"Computers are clever, so they'll know what I mean.\"","body":"Computers follow instructions exactly. Missing details or unclear words make them fail or do the wrong thing."},{"tag":"Popular idea","title":"\"If all the steps are there, the order doesn't matter.\"","body":"Sequence matters: putting on shoes before socks uses the same steps but gives a silly result."},{"tag":"Popular idea","title":"\"A variable never changes, like x in an equation.\"","body":"In a program a variable's value can be replaced as often as needed. It keeps only the newest value."}]},{"type":"cards","id":"words-table","eyebrow":"Pseudocode","title":"The words you need","items":[{"tag":"START / STOP","title":"Where it begins and ends","body":"Every algorithm needs a clear beginning and a clear end, so the person or computer following it knows when it is finished."},{"tag":"INPUT","title":"Get a value","body":"INPUT age gets a value (from the keyboard, a sensor…) and stores it in the variable age."},{"tag":"←","title":"Assignment","body":"years ← 18 − age works out the right-hand side and stores the answer in years."},{"tag":"OUTPUT","title":"Show a value","body":"OUTPUT years shows the value on screen (or prints it, or sends it)."}]},{"type":"cards","id":"example","eyebrow":"Worked example","title":"One algorithm, many answers","items":[{"tag":"Pseudocode","title":"Years until 18","body":"START\nINPUT age\nyears ← 18 − age\nOUTPUT \"Years until 18: \", years\nSTOP","code":true},{"tag":"Trace","title":"Input 12","body":"age = 12\nyears = 18 − 12 = 6\nOutput: Years until 18: 6","code":true},{"tag":"Trace","title":"Input 15","body":"age = 15\nyears = 18 − 15 = 3\nOutput: Years until 18: 3","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Robot friend","items":[{"title":"Sandwich robot","time":"20 minutes","need":["Bread, a spread and a blunt knife","A partner to be the 'robot'","Paper and a pen"],"steps":["Write an algorithm to make a jam sandwich, one instruction per line.","Your partner follows it exactly as written, doing nothing you didn't say.","Every time they get stuck or do something silly, improve that line.","Count how many lines your final algorithm needs."],"why":"A computer, like your 'robot', can't fill in gaps. Precise, ordered steps with a clear finish make an algorithm work.","safety":"Use a blunt knife and clean up after."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"What is an algorithm?","options":["A type of computer","A kind of cable","A set of precise steps to do a task"],"answer":2,"right":"Correct. Recipes and programs are both algorithms.","wrong":"Not quite. Think about a recipe."},{"question":"Why does an algorithm need a STOP?","options":["So it is clear when the task is finished","To look neat","To save electricity"],"answer":0,"right":"Correct. A definite finish tells the follower they are done.","wrong":"Not quite. What would happen without an end?"},{"question":"What does INPUT name do?","options":["Shows the name","Deletes the name","Gets a value and stores it in name"],"answer":2,"right":"Correct. INPUT gets a value and puts it in a variable.","wrong":"Not quite. Is it putting a value in, or showing one?"},{"question":"After total ← 5 then total ← 9, what is in total?","options":["5","9","14"],"answer":1,"right":"Correct. Assignment replaces the old value.","wrong":"Not quite. A variable keeps only its newest value."},{"question":"INPUT x, then y ← x + 3, then OUTPUT y. The input is 4. What is output?","options":["4","3","7"],"answer":2,"right":"Correct. y = 4 + 3 = 7.","wrong":"Not quite. Work out y step by step."},{"question":"Which is the best reason to use a variable?","options":["The same algorithm works for different inputs","It makes code longer","It stops errors happening"],"answer":0,"right":"Correct. Variables let one algorithm handle many values.","wrong":"Not quite. Think about the age example with different ages."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["what an algorithm is","why instructions must be precise and in order","why an algorithm needs a clear start and finish","what INPUT, OUTPUT and ← mean in pseudocode","what a variable is"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"algorithm","meaning":"A set of precise steps that completes a task."},{"word":"sequence","meaning":"Running steps one after another, in order."},{"word":"pseudocode","meaning":"A way to write algorithms that looks like code but is meant for people."},{"word":"input","meaning":"A value given to an algorithm."},{"word":"output","meaning":"A value an algorithm gives back or shows."},{"word":"variable","meaning":"A named place in memory that holds a value."},{"word":"assignment","meaning":"Storing a value in a variable, written ←."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize KS3 Computing: Algorithms"]}]},"overlay":null}