Lesson provided by Wi-Fighters

Debug Mission

Bug Hunt: Identify and Correct Errors

Move fast: spot the bug, fix the code, and clear four short rounds before the system crashes.

4
Rounds
Find + Fix
Goal
1. Predict

Say what the code should do before you change anything.

2. Test

Use one simple test case so you can see the bug clearly.

3. Fix

Change one thing at a time instead of rewriting everything.

4. Re-check

Run the checker again to confirm the bug is really gone.

Quick Guide To Error Types

Beginners usually see the same few bug types again and again. Start by asking: does the code fail to run, or does it run and give the wrong answer?

Syntax Error

The code cannot run because Python does not understand the way it is written.

How to fix it: Check punctuation, missing quotes, missing colons, or bad indentation.

Logic Error

The code runs, but the answer is wrong because the steps are wrong.

How to fix it: Compare the result to a test case and change the step that makes the wrong choice.

Input Error

The code is given the wrong kind of value or a value it was not expecting.

How to fix it: Check what the function receives and make sure it matches what the code needs.

Name Error

The code tries to use a variable or function name that does not exist.

How to fix it: Check spelling and make sure the name was created before it is used.

Fast Beginner Strategy: If the code runs but the result is wrong, start by looking for a logic error. Use one small test case, trace each step, and find the first place where the code does something different from what you expected.
Mission Progress

Earn 1 point for identifying the bug type and 1 point for fixing the code in each round.

Score 0 / 4
Level 1

Alphabet Tracker

The tracker should report a letter's position in the alphabet for a human reader.

Test case: d should return 4

Buggy Code

def find_letter_position(letter):
  alphabet_list = list("abcdefghijklmnopqrstuvwxyz")
  for index, current_letter in enumerate(alphabet_list):
    if current_letter == letter:
      return index
Run Commandfind_letter_position("d")

What Type Of Error Is It?

Repair Station

Edit the code so the test case returns the correct position.

Run Commandfind_letter_position("d")
Level 2

Odd Number Generator

The generator should return odd numbers from 1 to 9, but something in the code is blocking the mission.

Target output: [1, 3, 5, 7, 9]

Buggy Code

def make_odd_numbers()
        odds = []
        i = 1

        while i < 10:
                odds.append(i)
                i += 2

        return odds
Run Commandmake_odd_numbers()

What Type Of Error Is It?

Repair Station

Find the bug and fix the function so it produces [1, 3, 5, 7, 9].

Run Commandmake_odd_numbers()
Level 3

Average Score Stabilizer

The function should return the class average, but one test case causes a failure.

Test case: [] should return 0

Buggy Code

def average_score(scores):
        total = sum(scores)
        return total / len(scores)
Run Commandaverage_score([])

What Type Of Error Is It?

Repair Station

Find and fix the bug so this function works for all given tests.

Run Commandaverage_score([])
Level 4

Greeting Repair Drone

The function should greet the person by name, but the current version fails the mission check.

Test case: make_greeting() should return Hello, Ava!

Buggy Code

def make_greeting():
        name = "Ava"
        message = "Hello, " + student_name + "!"
        return message
Run Commandmake_greeting()

What Type Of Error Is It?

Repair Station

Find and fix the bug so the function returns the correct greeting.

Run Commandmake_greeting()
Victory Check

When all levels are green, you win.

Clear all levels to unlock the win message.
Example Multiple Choice Questions

Choose one option for each question, then submit after all are answered.

Question 1 of 8

Answer all questions to unlock quiz submission.

Score: Not Submitted / 8

Question 1 - Logic Error (Conditionals)

IF (num > 0)
{
  DISPLAY("Positive")
}
ELSE IF (num < 0)
{
  DISPLAY("Negative")
}
ELSE
{
  DISPLAY("Positive")
}

What is the issue?

Question 2 - Off-by-One Error (Loops)

FOR i ← 1 TO LENGTH(list)
{
  DISPLAY(list[i])
}

Assume lists are indexed starting at 0. What is the problem?

Question 3 - Incorrect Variable Update

total ← 0
FOR EACH item IN numbers
{
  total ← item
}
DISPLAY(total)

What does this code do incorrectly?

Question 4 - Boolean Logic Error

IF (score > 70 OR score < 90)
{
  DISPLAY("Pass")
}
ELSE
{
  DISPLAY("Fail")
}

What is the issue?

Question 5 - List Index Error

myList ← [10, 20, 30, 40]
DISPLAY(myList[4])

What happens?

Question 6 - Missing Initialization

FOR i ← 1 TO 5
{
  sum ← sum + i
}
DISPLAY(sum)

What is the issue?

Question 7 - Infinite Loop

i ← 1
WHILE (i < 10)
{
  DISPLAY(i)
}

What is the issue?

Question 8 - Function Return Issue

PROCEDURE add(a, b)
{
  result ← a + b
}
DISPLAY(add(3, 4))

What is the issue?