Setting a breakpoint

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

Setting a breakpoint

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How do you set a breakpoint in most code editors?
A Click in the margin beside the line number
B Type the word breakpoint at the end of the line
2. What does a breakpoint do when the program runs in debug mode?
A Deletes that line so the program skips it
B Pauses the program at that line so you can inspect it
3. Which way of running your program will actually stop at a breakpoint?
A Running in debug mode
B Running normally with the standard Run button
4. Your loop gives a wrong total after several passes. Where is the best place to set a breakpoint?
A On the very first comment at the top of the file
B On the line inside the loop that updates the total
5. How do you remove a breakpoint?
A Click the same marker beside the line number again
B Delete the whole file and start again

Match the Pairs

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

Left columnRight column
1Click beside line 12 ABreakpoint on line 8 with condition: i == 50
2Click the red dot on line 12 BA comment is not executed, so the program can never pause there. The breakpoint must go on a line of real code.
3Place a breakpoint on the line just before a suspected bug so you can inspect variables before the fault happens CBreakpoints only pause the program when it is run in debug mode. A normal run ignores them, so the program never stops.
4A conditional breakpoint only pauses the program when a condition is true Dtotal = total + price # breakpoint here, before the wrong total is printed
5Run the program normally, then expect it to pause at the breakpoint on line 5 ESets a breakpoint on line 12 so the program will pause there
6Set the breakpoint on a comment line: # check the total FRemoves the breakpoint from line 12

Definitions

breakpoint

Fill in the Blanks

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

1.
total = 0 __________() print(total)
2.
if score _ 100: breakpoint()
3.
if count __ 0: breakpoint() average = total / count
4.
for mark in marks: total += mark __________()
5.
for i in range(10): __ i == 7: breakpoint()

Spot the Error

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

Question 1
A scores = [72, 85, 90
B total = 0
C for s in scores:
D breakpoint()
E total = total + s
Question 2
A price = 20
B qty = 3
C if qty > 2
D breakpoint()
E price = price * 0.9
Question 3
A for i in range(1, 11):
B total = i * 2
C if i == 5:
D breakpoint
E print(total)
Question 4
A def average(a, b):
B total = a + b
C Breakpoint()
D return total / 2
Question 5
A age = int(input("Age: "))
B if age = 0:
C breakpoint()
D print("Age is", age)

Answer Key

Setting a breakpoint
Section A: Quick Questions
Q1
A — Click in the margin beside the line number
Q2
B — Pauses the program at that line so you can inspect it
Q3
A — Running in debug mode
Q4
B — On the line inside the loop that updates the total
Q5
A — Click the same marker beside the line number again
Section B: Match the Pairs
Q1
Click beside line 12 → Sets a breakpoint on line 12 so the program will pause there
Q2
Click the red dot on line 12 → Removes the breakpoint from line 12
Q3
Place a breakpoint on the line just before a suspected bug so you can inspect variables before the fault happens → total = total + price # breakpoint here, before the wrong total is printed
Q4
A conditional breakpoint only pauses the program when a condition is true → Breakpoint on line 8 with condition: i == 50
Q5
Run the program normally, then expect it to pause at the breakpoint on line 5 → Breakpoints only pause the program when it is run in debug mode. A normal run ignores them, so the program never stops.
Q6
Set the breakpoint on a comment line: # check the total → A comment is not executed, so the program can never pause there. The breakpoint must go on a line of real code.
Section C: Definitions
Q1
breakpoint — A marker set on a line of code (click beside the line number) that pauses the program there in debug mode, so you can inspect variables and step through the code.
Section D: Fill in the Blanks
Q1
total = 0 breakpoint() print(total)
Q2
if score > 100: breakpoint()
Q3
if count == 0: breakpoint() average = total / count
Q4
for mark in marks: total += mark breakpoint()
Q5
for i in range(10): if i == 7: breakpoint()
Section E: Spot the Error
Q1
A — The list is missing its closing bracket ]. This is a syntax error, so the program never starts and never reaches the breakpoint. It should be scores = [72, 85, 90].
Q2
C — The if line is missing its colon. This is a syntax error, so the conditional breakpoint inside the if block can never be reached. It should be if qty > 2:
Q3
D — breakpoint is only named, not called. Without the brackets the program never pauses at i == 5. It should be breakpoint().
Q4
C — Python is case-sensitive. Breakpoint with a capital B is not a built-in function and causes a NameError. It should be breakpoint().
Q5
B — A single = assigns a value and is not allowed in an if condition, so it is a syntax error. To compare for the breakpoint condition use ==: if age == 0: