Lab 9: Knowledge Check
These questions check your knowledge of concepts from this lab. Use the button at the bottom to show your answers once you've attempted them.
-
What does a breakpoint do in Thonny? (pick one or more)
- It interrupts a loop, forcing the code to continue after the loop.
- It will cause the debugger to fast-forward to the first breakpoint, and to pause at any breakpoint encountered once resumed.
- It triggers an error in your code on a specific line.
- It has no effect when you run your program normally.
-
Imagine that you set a breakpoint and run the debugger, but the program finishes without ever pausing. What are possible reasons for this? (pick one or more)
- Your breakpoint was set inside a function, but that function was never called.
- Your breakpoint was set inside of a conditional, but the condition for that branch was never True.
-
Your breakpoint was set inside a
for
loop, but the sequence value of the loop was an empty sequence, so the loop code never ran. - Your breakpoint was set inside of a while loop, but the condition for that loop was never True.
-
If you want to understand why an
optimism
test failed, you could: (pick one or more)
-
Add
print
and/ortrace
calls to your code. - Use the debugger to step through the code for the failing test.
-
Add a call to the
detailLevel
function with an argument of 1 or 2 before yourtestCase
call. - Add a series of simpler test cases to find the simplest one which doesn't work.
- Turn off your computer and go for a walk, take a nap, or chat with a friend about something unrelated to computer science.
-
Add
-
What is the primary purpose of using a
with
statement when opening a file?
-
To assign the file object to a variable, you must use a
with
statement. -
You must use
with
to open a file in writing mode. -
If you use
with
, the file will be closed automatically. -
Using a
with
statement allows you to iterate over the lines in a file.
-
To assign the file object to a variable, you must use a
-
When you open a file in 'write' mode and write some text into it, what happens? (pick one or more)
- If the file already exists, its contents are erased.
- The text is written into the file after any existing text that's already there.
- If the file doesn't already exist, it is created.
-
The text is written over what was there, and the old text is returned by the call to
.write
.