SubstitutePlans.com · Teacher phone guide
Bug Hunt: Debugging Printed Code
Teacher directions only. Student worksheets and the answer key are in the complete teacher PDF. This downloaded guide opens offline.
SubstitutePlans.com Technology and Computer Science · Computer Science SP-CS-006 · Free to print and use in your classroom · substituteplans.com Page 2 Bug Hunt: Debugging Printed Code Technology and Computer Science · Computer Science · Grades 9-12 · 50 minutes Time needed 50 minutes (one class period) Prep Copy the 2-page worksheet (one per student). Write the six bug types on the board (see Before class). Technology None. Student independence High. Students work alone, then compare fixes with a partner. Copies to make One 2-page worksheet per student Materials Pencils, Worksheet, Whiteboard or chalkboard Goal for today: Students will identify the type of bug in short printed programs and write a corrected line for each. Before the bell ☐ Copy the worksheet, one per student (2 pages). ☐ Write on the board the names of six bug types: syntax error (the code is not written correctly, so it will not run); name error (a name is misspelled); off-by-one error (a loop or count is one too many or too few); calculation error (the math is wrong); boundary error (a comparison leaves out an edge case); infinite loop (a loop never stops). ☐ Remind students that all code is fake practice: nothing needs to be run on a computer. ☐ Keep the answer key on your desk. Say this to start Every programmer writes bugs. Finding and fixing them is called debugging, and it is one of the most useful skills in computing. Today you will play bug detective. Each program on the worksheet has exactly one bug. Read the goal, read the code, predict what the computer would do, name the type of bug, and write the fixed line. SubstitutePlans.com Technology and Computer Science · Computer Science SP-CS-006 · Free to print and use in your classroom · substituteplans.com Page 3 Run of show Minutes What you do What students do 0–5 Take attendance. Hand out the worksheet and ask students to read the top box. Read “Reading the code.” 5–12 Read the six bug types from the board aloud. Then say: "Here is a sample. A program should print 10, but its line says print(5 + 4). The math is wrong, so that is a calculation error." Listen and follow along. 12–27 Tell students to do questions 1 through 6 (matching each program to its bug type). Walk around. Match each program to a bug type. 27–42 Tell students to do questions 7 through 12 (write the corrected line). Partners may compare fixes. Write the corrected line for each program. 42–47 Read the key aloud for questions 1 through 12. Students check their work. Mark answers and fix mistakes. 47–50 Collect all worksheets. Hand in the paper. If things go wrong • If students ask whether the computer will do something, tell them to read the code line by line and say what each line does. • If a student does not know what range(1, 5) does, tell them it counts 1, 2, 3, 4 and stops before 5. • If students argue over a fix, accept any change that makes the program meet its stated goal. • If students finish early, use the early finisher list. Early finishers • Write your own short program with one bug and trade it with a partner to debug. • For Program 4, explain in one sentence what “infinite loop” means and why a computer would seem to freeze. Support and challenge • Support: Let students skip Program 5 and 6 and focus on matching and fixing the first four programs. • Challenge: Ask students to find a second possible fix for Program 3 (use age >= 16 or age > 15). Notes for the teacher (you fill this in) Jot a few lines before you leave. A full Daily Sub Report is in the free Sub Survival Kit at SubstitutePlans.com. How far the class got / what to pick up next: Students who were especially helpful: SubstitutePlans.com Technology and Computer Science · Computer Science SP-CS-006 · Free to print and use in your classroom · substituteplans.com Page 4 Anything the teacher should know: