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
Open products.txt for writing. Make up the file handle. | with open("products.txt", "w") as f: | ^ *with open\(•products\.txt•, •w•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$ | |
Rewrite the following code to open a different CSV file. Make up its name. | with open("books.csv", "w", newline="") as f: | with open("records.csv", "w", newline="") as f: | ^ *with open\(•.+\.csv•, •w•, newline=••\) as f: *$ |
Complete the line. The file handle is file_to_read. | with open("stores.csv", "w", newline=__________ | "") as file_to_read: | "`"`) `as `file_to_read`: |
Complete the line. The file handle is f. | with open("stores.csv", "w", ______________ | newline="") as f: | newline="") as f: |
Open laws.csv to write. The file handle is x. | with open("laws.csv", "w", newline="") as x: | ^ *with open\(•laws\.csv•, •w•, newline=••\) as x: *$ | |
Open a CSV file to read. Use shorthand. Make everything up. | with open("cities.csv") as f: | ^ *with open\(•.+\.csv•\) as [a-zA-Z_][a-zA-Z0-9_]*: *$ | |
Open a CSV file to write. Make everything up. | with open("cats.csv", "w", newline="") as f: | ^ *with open\(•.+\.csv•, •w•, newline=••\) as [a-zA-Z_][a-zA-Z0-9_]*: *$ | |
Assign a CSV filename to a variable. Then use the variable to open the file for writing. Make everything up. | filename = "histories_of_the_world_before_Genghis_Khan.csv" with open(filename, "w", newline="") as f: |
^ *([a-zA-Z_][a-zA-Z0-9_]*) = •.+\.csv•\nwith open\(\1, •w•, newline=••\) as [a-zA-Z_][a-zA-Z0-9_]*: *$ | |
Open a text file and write a string to it. Make everything up. Remember to indent. | with open("greeting.txt", "w") as f: f.write("Hi") |
^ *with open\(•.+\.txt•, •w•\) as ([a-zA-Z_][a-zA-Z0-9_]*):\n \1\.write\(•.+•\) *$ | |
Open a text file and append a string to it. Make everything up. | with open("greeting.txt", "a") as f: f.write("Hi") |
^ *with open\(•.+\.txt•, •a•\) as ([a-zA-Z_][a-zA-Z0-9_]*):\n \1\.write\(•.+•\) *$ | |
|
|||