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 is the primary purpose of using a
withstatement when opening a file?
-
To assign the file object to a variable, you must use a
withstatement. -
You must use
withto open a file in writing mode. -
If you use
with, the file will be closed automatically. -
Using a
withstatement 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.
-
If you want to understand why an
optimismtest failed, you could: (pick one or more)
-
Add
printand/ortracecalls to your code. - Use the debugger to step through the code for the failing test.
- 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