Skip to content
KALANBLON
Show contents

Chapter 6 of 6 · 10 min

Quiz: files and data

Text files, CSV, JSON and the contact book: last quiz of this course. You need 70 % correct answers to pass it.

Quiz

5 questions · pass mark: 70%

  1. 1.The file grades.txt contains three lines. What does it contain after this code?

    One answer

    with open("grades.txt", "w", encoding="utf-8") as f:
        f.write("12\n")
  2. 2.Why use with open(...) as f rather than f = open(...)?

    One answer

  3. 3.A row read with csv.DictReader is {"quantity": "3"}. What is row["quantity"] * 2?

    One answer

  4. 4.Which statements about JSON are true? (several answers)

    Several answers possible

  5. 5.Complete the exception to catch when the save file doesn't exist yet.

    Complete the code

    try:
        contacts = load("contacts.json")
    except __________:
        contacts = []

Your progress is saved on this device. Create a free account to keep your progress on all your devices.