Which term describes the operation that connects a program to a file so that it can be used?
Open
Which term describes the point where there are no more lines left to read in a file?
End of file
Which term describes how a file is opened, for example to read it or to write it?
Mode
What is meant by 'readline()'?
A file method that returns the next line of a file as a string
What is meant by opening a file with the mode 'w'?
It creates the file if it does not exist and wipes anything already in it
What is meant by closing a file?
It finishes with the file and saves anything that was written
Which term describes a file of lines of characters that is kept in secondary storage?
Text file
What is meant by opening a file in the mode 'r'?
The file is read from the start and fails if it is missing
Which method is used to add each line read from a file to the end of an array?
append()
Why might a program store its data in a file rather than only in variables?
The data is kept after the program ends
Which is the correct order of the basic file handling operations?
Open, read or write, close
A program writes several lines to a file but ends without closing it. What is the likely effect?
Some of the written data may not be saved
What does readline() return when the end of the file is reached?
An empty string
Why is .strip() used on the value returned by readline()?
It removes the new line character from the end
A program writes five values to a text file, but when the file is opened all five are on one line. What is missing from each write?
A new line character
A loop that reads every line of a file never reads the next line inside the loop. What happens?
The loop never ends because the line never becomes empty
A file holds whole numbers, one on each line, and a program adds them to a total. Why is int() needed on each line?
Each line is read as a string
A file holds three lines, Red, Green and Blue. A program reads the first two into a and b, removes their new line characters, then prints b + a. What is printed?
GreenRed
A program stores a whole number in the variable total and writes it to a file with scoreFile.write(total). The program stops with an error. What should be done to fix it?
Total must be changed into a string with str()
A settings file always holds three lines: a name, a level and a sound setting, in that order. A program has called readline() once and stored the name. What does the next call to readline() return?
The level
A program reads a file that contains a blank line in the middle. What does readline() return when it reaches that blank line?
A new line character
A program opens a file, reads three lines and then closes it. Which value is used for those read and close operations?
The variable that holds the opened file
A program must read a file that could hold any number of lines, including none. Why is a while loop used rather than a set number of readline() calls?
It stops at the end of the file, whatever its length
We use cookies to enhance your experience. You can manage your preferences or learn more in our Cookie Policy.