1
2
3
4
5
6
7
8
9
10
11
12
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.
0,1,2,3,4,5,6,7,8,9,10,11
0
0
0
0
Fill in the blank to open a text file for writing. Make up the file name and handle. | with open(_______________ | "greet.txt", "w") as f: | ^ *•.+\.txt•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$ |
Open a file for writing. Make up the file name and handle. | with open("greet.txt", "w") as f: | ^ *with open\(•.+\.txt•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$ | |
The file name has been assigned to the variable file_name. The file handle is f. Open the file for writing. | with open(file_name, "w") as f: | with `open`(`file_name`, `"`w`"`) `as `f`: | |
Type the four characters that are missing from this code. | with open("catalog", "w") as file_to_open: | .txt | .txt |
Store a string in the file. Make up the string. Start by indenting. | with open("info.txt", "w") as my_file: | my_file.write("Hello, World!") | ^ * my_file\.write\(•.+•\) *$ |
Code the line that writes a string to a file. Make up the file handle and string. Start by indenting. | f.write("Hello, World!") | ^ * [a-zA-Z_][a-zA-Z0-9_]*\.write\(•.*•\) *$ | |
Assign a filename that ends in .txt to a variable. Then open the file for writing. Make everything up. | file_to_write_to = "products.txt" with open(file_to_write_to, "w") as f: |
^ *([a-zA-Z_][a-zA-Z0-9_]*) = •.+\.txt•\nwith open\(\1, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$ | |
Assign a string to a variable. Open a text file to write to. Using the variable, store the string in the file. | greeting = "Hello, World" with open("greet.txt", "w") as f: f.write(greeting) |
^ *([a-zA-Z_][a-zA-Z0-9_]*) = •.+•\nwith open\(•[a-zA-Z_][a-zA-Z0-9_]*\.txt•, •w•\) as ([a-zA-Z_][a-zA-Z0-9_]*):\n (\2)\.write\(\1\) *$ | |
The text stored in the file possible-answers.txt is "No". What text is stored in the file after the following code runs? | with open("possible-answers.txt", "w") as f:
f.write("Yes") |
"Yes" | ^ *•?Yes•? *$ |
Open a file for writing. Store your name in it. Make everything up. | with open("my_name.txt", "w") as f: f.write("Mark Myers") |
^ *with open\(•[a-zA-Z_][a-zA-Z0-9_]*\.txt•, •w•\) as ([a-zA-Z_][a-zA-Z0-9_]*):\n \1\.write\(•.+•\) *$ | |
|
|||