{"base":{"id":"cs11-14","subject":"Algorithms","title":"Finding and fixing errors in algorithms","scene":"mix","steps":[{"use":"cs11","mode":"errors","eyebrow":"Three kinds of error","title":"Syntax, logic, runtime","body":"Look at each program and the error it contains.","actions":[{"id":"e0","label":"Syntax"},{"id":"e1","label":"Logic"},{"id":"e2","label":"Runtime"}]},{"use":"code9","mode":"findbug","eyebrow":"Find the first wrong step","title":"Trace to the bug","body":"Trace with test data until the first line gives the wrong result.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"code9","mode":"tracefix","eyebrow":"Trace tables","title":"Check every row","body":"Use a trace table to check an algorithm line by line.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"py9","mode":"logic","eyebrow":"Fix it","title":"Runs, but wrong","body":"Fix a logic error and run again.","actions":[{"id":"run","label":"Run"},{"id":"fix","label":"Fix"}]},{"use":"cs11","mode":"quiz","look":"errors","eyebrow":"Check yourself","title":"Error type","body":"A program to average marks crashes when the list is empty.","question":"What type of error?","options":["Syntax error","Runtime error","Logic error"],"answer":1,"right":"Correct: division by zero while running.","wrong":"Not quite."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"Syntax","title":"Missing ENDIF","body":"IF x > 5 THEN OUTPUT \"big\"   ← needs ENDIF","code":true},{"tag":"Logic","title":"Wrong loop range","body":"FOR i ← 1 TO 9 (should be 10): misses the last item","code":true},{"tag":"Runtime","title":"Index out of range","body":"list of 5 items, accessing list[5]","code":true},{"tag":"Trace table","title":"Columns","body":"one column per variable, one row per step, plus output","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Only reading the code","body":"Trace with real values to find logic errors."},{"tag":"Mistake","title":"Fixing symptoms","body":"Find the cause, not just where the error shows."},{"tag":"Mistake","title":"Not re-testing","body":"Run all tests again after a fix."}]},{"type":"cards","id":"method","eyebrow":"Set out your answer","title":"Debugging","items":[{"tag":"1","title":"Reproduce","body":"Find input that shows the error."},{"tag":"2","title":"Trace","body":"Use a trace table."},{"tag":"3","title":"Locate","body":"First wrong value."},{"tag":"4","title":"Fix and retest","body":"Run all tests."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"History","title":"The first \"bug\"","body":"In 1947 engineers found a moth stuck in a relay of the Harvard Mark II computer and taped it in the log book as the \"first actual case of bug being found\"."},{"tag":"Tools","title":"Debuggers","body":"IDEs let you pause programs, step line by line and watch variables: an automatic trace table."}]},{"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":"Find","body":"max ← 0; FOR each x IN [−3, −7, −2]: IF x > max THEN max ← x. Output? What is wrong?\n\nAnswer: outputs 0; max should start as the first item, giving −2."},{"tag":"Challenge","title":"Find","body":"WHILE count < 10: OUTPUT count. What error?\n\nAnswer: infinite loop: count never changes (logic error)."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Bug hunt","time":"20 minutes","need":["Python","A friend"],"steps":["Each write a 6-line program with one hidden bug.","Swap and find the bug with a trace table."],"why":"Debugging others' code sharpens your own.","safety":"None."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"A syntax error…","options":["gives wrong output","crashes mid-run","breaks language rules"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"A logic error…","options":["runs but gives wrong results","stops compilation","is a typo in a keyword"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"A runtime error…","options":["is found by the compiler","occurs while the program runs","never crashes"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"Dividing by zero is a…","options":["syntax error","logic error","runtime error"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"A trace table records…","options":["variable values at each step","file sizes","test names only"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"An infinite loop is usually a…","options":["syntax error","logic error","hardware fault"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"After fixing a bug you should…","options":["delete tests","stop","retest everything"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"A missing bracket is a…","options":["syntax error","logic error","runtime error"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["identify syntax, logic and runtime errors","use trace tables to find errors","correct errors in algorithms","explain debugging steps"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"Syntax error","meaning":"Code breaks the language rules."},{"word":"Logic error","meaning":"Code runs but gives wrong results."},{"word":"Runtime error","meaning":"Error that occurs while running."},{"word":"Trace table","meaning":"Table of variable values during execution."},{"word":"Debugging","meaning":"Finding and fixing errors."}]},{"type":"sources","id":"sources","title":"Sources","items":["Smithsonian National Museum of American History: the first computer bug","Python documentation: errors and exceptions","Raspberry Pi Foundation, Isaac Computer Science: testing and debugging","BBC Bitesize, GCSE Computer Science: errors"]}]},"overlay":null}