A Smarter Way to Learn Python / Chapter 74 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

11

12

 

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to Trinket.


Post a review on Amazon for the paperback or the Kindle edition.


Email me to give me a compliment, complaint, or correction. I'll respond.


  All of my books include free interactive online exercises that make the knowledge stick.

A Smarter Way to Learn JavaScript
Shop for it at Amazon
A Smarter Way to Learn HTML and CSS
Shop for it at Amazon
A Smarter Way to Learn jQuery
Shop for it at Amazon

copyright © 2017 by Mark Myers. All rights reserved.

0,1,2,3,4,5,6,7,8,9,10,11

0

0

0

0


In this chapter you're learning to save a list to a ____ file. (All uppercase characters) JSON^ *JSON *$
Before you work with JSON files, you must _______ the module. import^ *import *$
Import the module that lets you work with JSON files. import json import `json
Open students.json for writing. The file handle is j. with open("students.json", "w") as j:with open("students.json", "w") as j:
Open a JSON file for writing. Make everything up. with open("students.json", "w") as j: ^ *with open\(•.+\.json•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$
You're writing the list named stuff to the JSON file that you've opened with the file handle j_file. Fill in the blank.   json.dump(stuff, ______) j_file ^ *j_file *$
You're writing the list named stuff to the JSON file that you've opened with the file handle j_file. Fill in the blank.   json.dump(_________________) stuff, j_file ^ *stuff, j_file *$
You're writing the list named stuff to the JSON file that you've opened with the file handle j_file. Fill in the blank.   ____________(stuff, jfile) json.dump ^ *json\.dump *$
Code the line that writes a list to a JSON file. Make everything up. Start by indenting.   json.dump(big_list, json_file) ^ * json\.dump\([a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]*\) *$
Open a JSON file for writing and write a file to it. Make everything up. with open("cats.json", "w") as j_file:
  json.dump(some_list, j_file)
^ *with open\(•.+\.json•, •w•\) as ([a-zA-Z_][a-zA-Z0-9_]*):\n json\.dump\([a-zA-Z_][a-zA-Z0-9_]*, \1\) *$
  1. In IDLE code a Python program that imports the json module...
  2. ...creates a list...
  3. ...and writes the list to a JSON file.
  4. Save the Python program to the Desktop and run it.
  5. Open the JSON file in IDLE.