Complete the code to open a file named 'log.txt' in append mode.
file = open('log.txt', '[1]')
To add data to the end of a file without deleting existing content, use mode 'a' for append.
Complete the code to write the string 'Hello\n' to the file object named 'file'.
file.[1]('Hello\n')
The write method adds text to the file.
Fix the error in the code to properly close the file after writing.
file = open('log.txt', 'a') file.write('Data\n') file.[1]()
Always close a file after writing to save changes and free resources.
Fill both blanks to append the number 5 as a string to the file 'numbers.txt'.
with open('numbers.txt', '[1]') as f: f.[2]('5\n')
Open the file in append mode 'a' and use the write method to add text.
Fill all three blanks to append squares of numbers 1 to 3 to 'squares.txt', each on a new line.
with open('squares.txt', '[1]') as f: for i in range(1, 4): f.[2](str(i[3]2) + '\n')
Open in append mode 'a', use write to add text, and use '**' to square the number.
