{"base":{"id":"cs9-01","subject":"Algorithms","title":"Reading and repairing pseudocode","scene":"code9","steps":[{"mode":"buggy","eyebrow":"Trace it","title":"Does it always work?","body":"This algorithm should output the larger of two numbers. Choose values for a and b and run it line by line. Try several pairs: does it always give the larger one?","controls":[{"id":"a","label":"a","min":1,"max":10,"step":1,"value":3},{"id":"b","label":"b","min":1,"max":10,"step":1,"value":8}],"actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"mode":"findbug","eyebrow":"Find the bug","title":"The first wrong step","body":"Trace with a = 3 and b = 8. At each line, compare what happens with what should happen. The first step that gives a wrong result is where the bug is.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"mode":"fixed","eyebrow":"Repair and retest","title":"Run the same case again","body":"Swap the two outputs and trace again with the same values. Then test other pairs, including a = b. A repair isn't finished until you have tested it.","controls":[{"id":"a","label":"a","min":1,"max":10,"step":1,"value":3},{"id":"b","label":"b","min":1,"max":10,"step":1,"value":8}],"actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Spot the step","body":"An algorithm should output 'Pass' when mark ≥ 50. It says: IF mark > 50 THEN OUTPUT \"Pass\".","question":"Which input shows the bug?","options":["70","20","50"],"answer":2,"right":"Correct. 50 should pass, but 50 > 50 is false. The condition should be mark >= 50.","wrong":"Not quite. Test the boundary value.","look":"findbug"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"If it works for one input, it's correct.\"","body":"One test proves very little. The buggy algorithm works whenever a is bigger than b."},{"tag":"Popular idea","title":"\"Debugging means rewriting the whole program.\"","body":"Find the first wrong step and fix just that, then retest."},{"tag":"Popular idea","title":"\"Pseudocode is a real programming language.\"","body":"Pseudocode is a clear way to write an algorithm for people. It isn't run by a computer exactly as written."}]},{"type":"cards","id":"code","eyebrow":"Pseudocode","title":"Two versions","items":[{"tag":"Buggy","title":"Larger of two","body":"INPUT a\nINPUT b\nIF a < b THEN\n    OUTPUT a\nELSE\n    OUTPUT b\nENDIF","code":true},{"tag":"Fixed","title":"Larger of two","body":"INPUT a\nINPUT b\nIF a < b THEN\n    OUTPUT b\nELSE\n    OUTPUT a\nENDIF","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Instruction bugs","items":[{"title":"Sandwich algorithm","time":"15 minutes","need":["Paper","A partner"],"steps":["Write step-by-step instructions for making a sandwich (or tying a shoe).","Your partner follows them exactly, doing only what is written.","Note the first step where things go wrong.","Fix that step and test again."],"why":"Computers follow instructions exactly, so a single unclear or wrong step breaks the whole algorithm.","safety":"Use pretend food or take care with knives."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"What does 'trace' an algorithm mean?","options":["Copy it out","Follow it step by step with test values","Delete it"],"answer":1,"right":"Correct. You track what happens at each step.","wrong":"Not quite. Think of following a path."},{"question":"x ← 5; x ← x + 3; OUTPUT x. What is output?","options":["5","8","3"],"answer":1,"right":"Correct. x becomes 5, then 8.","wrong":"Not quite. Track x after each line."},{"question":"IF n > 10 THEN OUTPUT \"Big\" ELSE OUTPUT \"Small\". n = 10 outputs…","options":["Small","Big","Nothing"],"answer":0,"right":"Correct. 10 > 10 is false.","wrong":"Not quite. Is 10 greater than 10?"},{"question":"What should you do after fixing a bug?","options":["Nothing","Run the same test again","Delete the test"],"answer":1,"right":"Correct. Retesting checks that the fix worked.","wrong":"Not quite. How do you know it's fixed?"},{"question":"Which symbol means 'is stored in' in pseudocode?","options":["=","→","←"],"answer":2,"right":"Correct. x ← 5 stores 5 in x.","wrong":"Not quite. Assignment arrow."},{"question":"An algorithm to find the smaller of two numbers outputs the larger. The bug is probably in…","options":["the comparison or the outputs","the INPUT lines","the ENDIF"],"answer":0,"right":"Correct. The decision or outputs are swapped.","wrong":"Not quite. Where is the choice made?"}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["how to trace an algorithm with sample inputs","how to find the first incorrect step","how to repair an algorithm","why you must retest after a fix"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"algorithm","meaning":"A set of steps to solve a problem."},{"word":"pseudocode","meaning":"A structured, readable way to write an algorithm."},{"word":"trace","meaning":"Follow an algorithm step by step, recording values."},{"word":"bug","meaning":"An error in an algorithm or program."},{"word":"debug","meaning":"Find and fix bugs."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize KS3 Computer Science","Raspberry Pi Foundation, Computing curriculum resources"]}]},"overlay":null}