Complete the code to open a file named 'data.txt' for reading.
file = open('data.txt', '[1]')
The mode 'r' opens the file for reading only.
Complete the code to open a file named 'log.txt' for appending new data.
file = open('log.txt', '[1]')
The mode 'a' opens the file for appending, so new data is added at the end.
Fix the error in the code to open a file for writing only if it does not exist.
file = open('newfile.txt', '[1]')
The mode 'x' creates a new file and opens it for writing, but fails if the file already exists.
Fill both blanks to open a file named 'report.txt' for reading and writing.
file = open('report.txt', '[1][2]')
The mode 'r+' opens the file for both reading and writing without truncating it.
Fill the blanks to create a dictionary comprehension that maps filenames to their sizes only if size is greater than 1000 bytes.
sizes = {filename: os.path.getsize(filename) for filename in files if os.path.getsize(filename) [1] [2]The condition checks if the file size is greater than 1000 bytes, so the operator is '>' and the number is 1000.