Complete the code to create a new file named 'notes.txt'.
file = open('notes[1]', 'w')
The file extension '.txt' is used for plain text files. This code opens (or creates) a file named 'notes.txt' for writing.
Complete the code to close the file after writing.
file = open('data[1]', 'w') file.write('Hello') file.[2]()
The blank in the filename should be '.txt' to create a text file named 'data.txt'. The method to close the file is 'close()'.
Fix the error in the code to create a file named 'report.doc'.
file = open('report[1]', 'w')
The file extension '.doc' is used for Microsoft Word documents. This code creates a file named 'report.doc'.
Fill both blanks to create a file named 'summary.csv' and write 'data' into it.
file = open('summary[1]', '[2]') file.write('data') file.close()
The file extension '.csv' is used for comma-separated values files. The mode 'w' opens the file for writing.
Fill all three blanks to create a file named 'logfile.log', write 'error' into it, and then close it.
file = open('logfile[1]', '[2]') file.write('[3]') file.close()
The file extension '.log' is used for log files. The mode 'w' opens the file for writing. The string 'error' is written into the file.