A Smarter Way to Learn Python / Chapter 62 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


Fill in the blank. ____ open("whatever.txt", "w") as file_to_work_with: with^ *with *$
When you open a file by writing with at the beginning of the line, Python _______ the file automatically after you write to it. closes^ *closes *$
Fill in the blank. _____________("whatever.txt", "w") as file_to_work_with:with open with `open
The name of the file is "names.txt". Fill in the blank. ____________________________, "w") as f:with open("names.txt"with open("names.txt"
What is the file handle here? with open("cities.txt", "w") as data: data ^ *data *$
Open the file "x.txt" so you can write to it. Make up the file handle. with open("x.txt", "w") as the_file_to_write_to: ^ *with open\(•x.txt•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$
Open a file so you can write to it. Make up the file name and file handle. with open("recipes.txt", "w") as f: ^ *with open\(•[-\w^&'@{}[\],$=!#().%+~ ]+\.txt•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$
If the Python program that opens a file is in the folder named python, the text file is in the folder named _______, according to this code. with open("recipes.txt", "w") as f: python ^ *python *$
Open a text file that's in a different folder than the Python program that's opening it. Assume you're in Windows. Make everything up. with open("text_files\recipes.txt", "w") as f: ^ *with open\(•.+\\.+\.txt•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$
Open a text file that's in a different folder than the Python program that's opening it. Assume you're in OS X or Linux. Make everything up. with open("text_files/recipes.txt", "w") as f: ^ *with open\(•.+\/.+\.txt•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$
  1. There's no live coding for this chapter. Instead, I want you to get ready to run Python on your computer so you can start working with files, beginning with the next chapter. Follow the instructions in Appendix D of the book to run Python in IDLE on your computer. The instructions include how to check whether Python 3 is installed on your computer and, if not, how to install it.