Title: Competency 7 Practice Quiz
Course: Programming Fundamentals I > Section: Practice Quizzes

Q: What three steps must be taken by a program when it uses a file?
- (1)Open the file. (2) Process the file. (3)Close the file
- (1)Open the file (2) Save the file (3) Execute the code
- (1)Open the file (2) Compile the code (3) Execute the code
- (1)Open the file (2) Process the file (3) Execute the code
A: (1)Open the file. (2) Process the file. (3)Close the file

Q: What are the two types of file access?
A: sequential and direct

Q: If a file already exists what happens to it if you try to open it as an output file (using the ' w' mode)?
Feedback: The file’s contents are erased

Q: In what mode do you open a file if you want to write data to it, but you do not want to erase the file’s existing contents?
- append mode
- Read mode
- Write
- Add
A: append mode

Q: Write a short program that uses a for loop to write the numbers 1 through 10 to a file.
Feedback: outfile = open ('numbers. txt', 'w') for num in range (1, 11) : outfile. write (str (num) + ' \n' ) outfile. close( )

Q: What does it mean when the readline method returns an empty string?
- it has attempted to read beyond the end of a file
- the file is empty
- the file does not include string data
- it read to the end of file
A: it has attempted to read beyond the end of a file

Q: A/An _________ _________ is a file that contains data that has not been converted to text
A: Binary file

Q: A/An _________ _________ is a file from which data is read
A: input file

Q: A/An _________ is a function that belongs to an object
A: method

Q: _________ _________ marks the location of the next item to be read from a file
A: Read position