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 its contents.
Complete the code to write the string 'Hello' into a file.
with open('greeting.txt', 'w') as file: file.[1]('Hello')
The 'write' method adds text to the file.
Fix the error in the code to properly close the file after reading.
file = open('info.txt', 'r') content = file.read() file.[1]()
The 'close' method properly closes the file to free resources.
Fill both blanks to create a dictionary with file names as keys and their sizes in bytes as values.
file_sizes = {filename: [1] for filename in files if [2]Use os.path.getsize(filename) to get file size and filter files ending with '.txt'.
Fill all three blanks to create a dictionary with uppercase file names as keys and their last modified time if size is greater than 1000 bytes.
file_info = [1]: os.path.getmtime([2]) for [3] in files if os.path.getsize([3]) > 1000
Use uppercase filename as key, original filename for functions, and iterate with 'filename'.