Breakpoints in an editor

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

Breakpoints in an editor

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does a breakpoint do when the program runs?
A It pauses the program on that line so you can inspect it
B It deletes that line from the program
2. How do you usually set a breakpoint in a code editor?
A Click in the margin beside the line number
B Type the word breakpoint at the end of the line
3. A breakpoint is on line 6. You run the program in debug mode. What happens?
A It pauses before line 1 and never runs the rest
B It runs normally until it reaches line 6, then pauses
4. When the program is paused at a breakpoint, has the breakpoint line already run?
A No, it is about to run
B Yes, it has just finished running
5. How do you remove a breakpoint you no longer need?
A Delete the whole program and start again
B Click the breakpoint marker again

Match the Pairs

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

Left columnRight column
1breakpoint ASets a breakpoint on line 5 so the program will pause there
2Click beside line 5 in the editor BClick the red dot beside line 5 again
3Running in debug mode makes the program stop at the breakpoint before the marked line runs CA marker on a line that pauses the program there when it runs, so you can inspect variables
4Removing a breakpoint by clicking the red dot again so the program no longer pauses there DRun > Start Debugging (F5)
5Set a breakpoint on a blank line or comment, then run the program normally (not in debug mode) EThe program will not pause. Breakpoints only work when the program is run in debug mode and sit on a line of code that runs.
6Breakpoint set on line 10 but the bug happens on line 4 FThe program pauses after the bug has already happened. Set the breakpoint on or just before the suspect line, such as line 4.

Definitions

breakpoint

Fill in the Blanks

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

1.
total = 0 __________() print(total)
2.
# Click beside a line to set a __________ print("Hi")
3.
age = 16 breakpoint() print(___)
4.
# The program ______ at the breakpoint x = 5
5.
# Click the red dot again to ______ it print("Done")

Spot the Error

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

Question 1
A total = 0
B breakpoint
C for n in [2, 4, 6]:
D total += n
E print(total)
Question 2
A price = 20
B qty = 3
C total = price * qty
D Breakpoint()
E print(total)
Question 3
A def area(w, h):
B result = w * h
C pause()
D return result
Question 4
A count = 0
B while count < 3:
C breakpoint():
D count += 1
Question 5
A x = 8
B y = x + 2
C breakpoint()
D brakepoint()

Answer Key

Breakpoints in an editor
Section A: Quick Questions
Q1
A — It pauses the program on that line so you can inspect it
Q2
A — Click in the margin beside the line number
Q3
B — It runs normally until it reaches line 6, then pauses
Q4
A — No, it is about to run
Q5
B — Click the breakpoint marker again
Section B: Match the Pairs
Q1
breakpoint → A marker on a line that pauses the program there when it runs, so you can inspect variables
Q2
Click beside line 5 in the editor → Sets a breakpoint on line 5 so the program will pause there
Q3
Running in debug mode makes the program stop at the breakpoint before the marked line runs → Run > Start Debugging (F5)
Q4
Removing a breakpoint by clicking the red dot again so the program no longer pauses there → Click the red dot beside line 5 again
Q5
Set a breakpoint on a blank line or comment, then run the program normally (not in debug mode) → The program will not pause. Breakpoints only work when the program is run in debug mode and sit on a line of code that runs.
Q6
Breakpoint set on line 10 but the bug happens on line 4 → The program pauses after the bug has already happened. Set the breakpoint on or just before the suspect line, such as line 4.
Section C: Definitions
Q1
breakpoint — A marker set on a line of code that pauses the program there when it runs, so you can inspect variables and step through. Set one by clicking beside the line; click again to remove it.
Section D: Fill in the Blanks
Q1
total = 0 breakpoint() print(total)
Q2
# Click beside a line to set a breakpoint print("Hi")
Q3
age = 16 breakpoint() print(age)
Q4
# The program pauses at the breakpoint x = 5
Q5
# Click the red dot again to remove it print("Done")
Section E: Spot the Error
Q1
B — breakpoint is a function, so it needs brackets to be called. Without them nothing pauses. It should be breakpoint().
Q2
D — Python is case sensitive, so Breakpoint() is not defined and causes a NameError. It should be breakpoint() in lowercase.
Q3
C — pause() is not a Python function, so it would cause a NameError. The line that pauses the program so you can inspect result is breakpoint().
Q4
C — A function call does not end with a colon, so this is a syntax error. It should be breakpoint() with no colon.
Q5
D — The name is misspelled, so Python raises a NameError and the program does not pause. It should be breakpoint().