Check your understanding of the previous reading: opening, reading and closing files, processing a file with a for loop, and what causes a FileNotFoundError.
True or false: After opening a file, you should always close a file.
Select one answer, then check.
close method: if you open a door, you need to close the door.True or false: A for loop will process a file sentence-by-sentence.
Select one answer, then check.
for loop gives you one line at a time, not one sentence.for loop processes a file line-by-line: each line, not each sentence.True or false: The open function consumes a string representing a path and returns a string of the file's data.
Select one answer, then check.
open does consume a path, but it returns a file object; you get the data as a string by calling read on that object.open returns a file object, not the file's data; the read method returns the contents as a string.Given the file named grades.txt with the following contents:
90, 85, 100
And the following python code:
grade_file = open("grades.txt")
grade_data = grade_file.read()
What will be the type of grade_data?
Select one answer, then check.
read doesn't split the file into lines or values; it returns the whole contents at once.read returns it as one piece.read returns the contents of the file as a single string: "90, 85, 100".read returns the contents of the file as a single string.grade_file is the file object that open returned; grade_data holds what read returned, a string.Which of the following are causes of a FileNotFoundError?
Select every answer that applies, then check.
open can't find it.open looks for a file with exactly that name, and there is none.opne, so Python raises a NameError before any file is looked for.open needs the path as an argument; without it Python raises a TypeError, not a FileNotFoundError.