Automated debugging with AI tools

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Automated debugging with AI tools

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. You get a Python error and want an AI tool to help. Which prompt gives it the best chance of finding the cause?
A Write 'my code is broken, fix it' without any code or error
B Paste your code, the full traceback and what the program should do
2. What is the most useful part of an error to paste into an AI tool?
A The whole traceback, including the error type and line number
B Only the word 'Error' from the message
3. Your program runs with no error, but it prints 12 when it should print 15. What should you tell the AI?
A The expected output is 15, the actual output is 12, and here is the code
B There is no error message, so there is nothing to ask the AI about
4. Which kind of error is describing expected vs actual output MOST useful for?
A A logic error, where the program runs but gives the wrong result
B A syntax error, where Python refuses to run the program at all
5. An AI tool suggests a fix for your bug. What should you do next?
A Paste it in and assume it works because an AI wrote it
B Read it to understand why it works, then run it and test it

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Traceback (most recent call last): File "main.py", line 5 ZeroDivisionError: division by zero Aassert average([10, 20, 30]) == 20
2Expected: 15, Actual: 5 BThe fix was not understood or tested, but AI suggestions can be wrong and must always be checked
3After an AI suggests a fix, you verify it by running the program again with test data and checking the output CA description of expected vs actual output that helps an AI find a logic error where there is no error message
4A good debugging prompt includes the code, the error message and the expected behaviour Dprompt = code + traceback + "Expected: total of 15"
5Prompt: "My code doesn't work. Fix it." EThe error message you paste into an AI tool so it can see the error type and the line where the program failed
6Paste the AI's fixed code into the project and submit it without running it FThe prompt gives no code, no error message and no expected behaviour, so the AI can only guess at the cause

Definitions

AI debugging

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
def add(a, b): return a + b ______ add(2, 3) == 5
2.
try: result = 10 / 0 except _________________:
3.
for price in prices: total = total _ price
4.
expected = 5 actual = average([4, 6]) print(expected __ actual)
5.
def average(nums): return sum(nums) / ___(nums)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A def add_gst(price):
B rate = 0.1
C return price * rate
D print(add_gst(100))
Question 2
A code = "print(total)"
B error = "NameError: total
C prompt = code + " " + error
D print(prompt)
Question 3
A def double(n):
B return n * 2
C assert double(4) = 8
Question 4
A expected = [1, 2, 3]
B actual = sorted[3, 1, 2]
C print(expected == actual)
Question 5
A def is_adult(age):
B # 18 should count as adult
C return age > 18

Answer Key

Automated debugging with AI tools
Section A: Quick Questions
Q1
B — Paste your code, the full traceback and what the program should do
Q2
A — The whole traceback, including the error type and line number
Q3
A — The expected output is 15, the actual output is 12, and here is the code
Q4
A — A logic error, where the program runs but gives the wrong result
Q5
B — Read it to understand why it works, then run it and test it
Section B: Match the Pairs
Q1
Traceback (most recent call last): File "main.py", line 5 ZeroDivisionError: division by zero → The error message you paste into an AI tool so it can see the error type and the line where the program failed
Q2
Expected: 15, Actual: 5 → A description of expected vs actual output that helps an AI find a logic error where there is no error message
Q3
After an AI suggests a fix, you verify it by running the program again with test data and checking the output → assert average([10, 20, 30]) == 20
Q4
A good debugging prompt includes the code, the error message and the expected behaviour → prompt = code + traceback + "Expected: total of 15"
Q5
Prompt: "My code doesn't work. Fix it." → The prompt gives no code, no error message and no expected behaviour, so the AI can only guess at the cause
Q6
Paste the AI's fixed code into the project and submit it without running it → The fix was not understood or tested, but AI suggestions can be wrong and must always be checked
Section C: Definitions
Q1
AI debugging — Giving an AI tool your code, the error message and the expected behaviour so it suggests a cause and a fix, which you must still understand and test yourself.
Section D: Fill in the Blanks
Q1
def add(a, b): return a + b assert add(2, 3) == 5
Q2
try: result = 10 / 0 except ZeroDivisionError:
Q3
for price in prices: total = total + price
Q4
expected = 5 actual = average([4, 6]) print(expected == actual)
Q5
def average(nums): return sum(nums) / len(nums)
Section E: Spot the Error
Q1
C — This is a logic error. The program runs with no error message, but it prints 10.0 when the expected output is 110.0. Describing expected vs actual output helps an AI tool find it. The line should be return price * (1 + rate). You still have to test the AI's fix.
Q2
B — The string is missing its closing quote, which causes a SyntaxError. The error message you paste into an AI prompt must be stored as a complete string: error = "NameError: total".
Q3
C — assert needs the comparison operator == and not the assignment symbol =. The test should be assert double(4) == 8. Writing a test like this lets you verify that an AI-suggested fix really works.
Q4
B — sorted is a function, so it must be called with round brackets: sorted([3, 1, 2]). Square brackets cause a TypeError, and pasting that traceback into an AI tool would point you to this line.
Q5
C — This is a boundary logic error. The comment says 18 should count as an adult, but > leaves 18 out. The line should be return age >= 18. Test the AI's fix with the boundary value 18.