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.

  1. What does a breakpoint do in Thonny? (pick one or more)
    1. It interrupts a loop, forcing the code to continue after the loop.
    2. It will cause the debugger to fast-forward to the first breakpoint, and to pause at any breakpoint encountered once resumed.
    3. It triggers an error in your code on a specific line.
    4. It has no effect when you run your program normally.
  2. 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)
    1. Your breakpoint was set inside a function, but that function was never called.
    2. Your breakpoint was set inside of a conditional, but the condition for that branch was never True.
    3. 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.
    4. Your breakpoint was set inside of a while loop, but the condition for that loop was never True.
  3. If you want to understand why an optimism test failed, you could: (pick one or more)
    1. Add print and/or trace calls to your code.
    2. Use the debugger to step through the code for the failing test.
    3. Add a call to the detailLevel function with an argument of 1 or 2 before your testCase call.
    4. Add a series of simpler test cases to find the simplest one which doesn't work.
    5. Turn off your computer and go for a walk, take a nap, or chat with a friend about something unrelated to computer science.
  4. What is the primary purpose of using a with statement when opening a file?
    1. To assign the file object to a variable, you must use a with statement.
    2. You must use width to open a file in writing mode.
    3. If you use with, the file will be closed automatically.
    4. Using a with statement allows you to iterate over the lines in a file.
  5. When you open a file in 'write' mode and write some text into it, what happens? (pick one or more)
    1. If the file already exists, its contents are erased.
    2. The text is written into the file after any existing text that's already there.
    3. If the file doesn't already exist, it is created.
    4. The text is written over what was there, and the old text is returned by the call to .write.

Table of Contents