Debugging Strategies Lesson Plan Answer Key
 
Debugging Answer Key - Teacher Guide

🐛 Debugging Answer Key - Teacher Guide

Quick Reference for Debugging Strategies Day 2

📚 Main Learning Objective:

Students will evaluate error messages to systematically resolve syntax and logic errors in Python code.

1

Lots of Hurdles

1 Error
Error #1 Line 1
⚠️ SYNTAX ERROR: Missing Function Definition
Error Message: NameError: name 'turn_right' is not defined
What's Wrong: The turn_right() function is called in jump_hurdle() but is never defined in the starter code.
✅ How to Fix:

Add the turn_right() function definition before it is used:

def turn_right(): turn_left() turn_left() turn_left()

Teaching Tip: Emphasize that functions must be defined before they are called. This is a common error for beginning programmers.

2

Big Tower

3 Errors
Error #1 Line 6
⚠️ LOGIC ERROR: Incorrect Condition
What's Wrong: The condition while facing_north(): should be while not_facing_north():
✅ How to Fix:
while facing_north(): while not_facing_north():

Why: Karel should keep turning left UNTIL facing north, not WHILE already facing north.

Teaching Tip: This is a logic error that won't produce an error message but will cause incorrect behavior. Have students trace through what happens with the wrong condition.

Error #2 Line 13
⚠️ LOGIC ERROR: Duplicate Action
What's Wrong: There is an extra put_ball() inside the while loop
✅ How to Fix:

Remove the duplicate put_ball() statement. The correct structure should be:

while front_is_clear(): put_ball() move() put_ball() while front_is_clear(): put_ball() move()

Why: This causes Karel to place two balls per square, which is incorrect.

Error #3 Line 17
⚠️ SYNTAX ERROR: Missing Underscore
Error Message: NameError: name 'buildtower' is not defined
What's Wrong: Function name is buildtower() but should be build_tower()
✅ How to Fix:
buildtower() build_tower()

Teaching Tip: Function names must match EXACTLY, including underscores. Python is case-sensitive and space-sensitive.

3

Random Hurdles

5 Errors
Error #1 Line 8
⚠️ SYNTAX ERROR: Colon Instead of Parenthesis
Error Message: SyntaxError: invalid syntax
What's Wrong: turn_right(): should be turn_right() (no colon)
✅ How to Fix:
turn_right(): turn_right()

Why: Colons are only used after function definitions, loops, and conditionals, not when calling functions.

Error #2 Lines 9-10
⚠️ SYNTAX ERROR: Incorrect Indentation
Error Message: IndentationError: unexpected indent
What's Wrong: Lines 9-10 are indented as if they're inside a block, but there's no reason for them to be indented
✅ How to Fix:
turn_right(): move() turn_right() turn_right() move() turn_right()

Why: These commands should all be at the same indentation level within the jump_hurdle() function.

Teaching Tip: This error was caused by the colon on line 8. Once the colon is removed, the indentation also needs to be fixed.

Error #3 Before Line 6
⚠️ SYNTAX ERROR: Missing Function Definition
Error Message: NameError: name 'turn_right' is not defined
What's Wrong: The turn_right() function is never defined
✅ How to Fix:

Add the function definition before jump_hurdle():

def turn_right(): turn_left() turn_left() turn_left()
Error #4 Line 14
⚠️ LOGIC ERROR: Incorrect Range
What's Wrong: for i in range(14): should be for i in range(13):
✅ How to Fix:
for i in range(14): for i in range(13):

Why: Karel needs to move 13 times to cross 14 columns (moves between columns, not on them). This will cause Karel to crash into the wall.

Teaching Tip: This is the "fence post problem" - if you have 14 fence posts, you only need 13 sections of fence between them.

Error #5 Line 17
⚠️ SYNTAX ERROR: Incorrect Else Syntax
Error Message: SyntaxError: invalid syntax
What's Wrong: else front_is_clear(): should be just else:
✅ How to Fix:
else front_is_clear(): else:

Why: The else statement doesn't take a condition. It automatically handles all cases not covered by the if statement.

Teaching Tip: If students want to check a second condition, they should use elif, not else.

Error #6 Line 18
⚠️ SYNTAX ERROR: Incorrect Indentation
Error Message: IndentationError: expected an indented block
What's Wrong: move() needs to be indented to be inside the else block
✅ How to Fix:
else: move() else: move()

Why: After a colon in Python, the next line(s) must be indented to show they belong to that block.

📊 Error Summary

Total Errors Across All Problems: 9

  • Syntax Errors: 6 (Missing definitions, incorrect colons, indentation, function names)
  • Logic Errors: 3 (Wrong conditions, incorrect range, duplicate actions)
Last updated  2025/10/08 01:36:12 PDTHits  39