Examplary
Start for free
Oak ComputingTest · Computing

Writing to text files

The starter and exit quiz of the lesson “Writing to text files”, from the unit “Programming: dictionaries and data files” (Year 11 Computing) by Oak National Academy.

Free to use. Edit it, share it and hand it out to your students.

Oak National Academy

12 questions

  1. Which file mode is used to read a file in Python?
  2. To read a text file line by line, you should use the ___ method.
  3. Which method returns all lines of a file as a list?
  4. Which of the following is the correct way to read the entire content of a text file in Python?
  5. Which is the Python method which removes any leading and trailing whitespaces or characters that you specify?
  6. Saving program data to an external ___ allows you to use that data again.
  7. What happens when you open a file in write ("w") mode?
  8. To add new data to an existing file without erasing its content, you should open the file in ___ mode.
  9. What will the following code do?file = open("example.txt", "w")file.write("Hello, world!")file.close()
  10. To make sure changes are saved when writing to a file, it is good practice to ___ the file after writing.
  11. Which of the following is the correct way to open a file, write text to it, and close it properly in Python?
  12. Which character is used to ensure text is added to a new line in a file?

License: OGL

Writing to text files · Examplary