Identifying and Correcting Errors (Wi-Fighters)
This page will teach you about identifying and correcting errors.
Lesson provided by Wi-Fighters
Bug Hunt: Identify and Correct Errors
Move fast: spot the bug, fix the code, and clear four short rounds before the system crashes.
Say what the code should do before you change anything.
Use one simple test case so you can see the bug clearly.
Change one thing at a time instead of rewriting everything.
Run the checker again to confirm the bug is really gone.
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.
Earn 1 point for identifying the bug type and 1 point for fixing the code in each round.
Alphabet Tracker
The tracker should report a letter's position in the alphabet for a human reader.
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
What Type Of Error Is It?
Repair Station
Edit the code so the test case returns the correct position.
Odd Number Generator
The generator should return odd numbers from 1 to 9, but something in the code is blocking the mission.
Buggy Code
def make_odd_numbers()
odds = []
i = 1
while i < 10:
odds.append(i)
i += 2
return odds
What Type Of Error Is It?
Repair Station
Find the bug and fix the function so it produces [1, 3, 5, 7, 9].
Average Score Stabilizer
The function should return the class average, but one test case causes a failure.
Buggy Code
def average_score(scores):
total = sum(scores)
return total / len(scores)
What Type Of Error Is It?
Repair Station
Find and fix the bug so this function works for all given tests.
Greeting Repair Drone
The function should greet the person by name, but the current version fails the mission check.
Buggy Code
def make_greeting():
name = "Ava"
message = "Hello, " + student_name + "!"
return message
What Type Of Error Is It?
Repair Station
Find and fix the bug so the function returns the correct greeting.
When all levels are green, you win.
Choose one option for each question, then submit after all are answered.
Question 1 of 8
Answer all questions to unlock quiz submission.
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?