Complete the code to open a file named 'output.txt' for writing.
file = open('output.txt', '[1]')
Use 'w' mode to open a file for writing. It creates the file if it doesn't exist and overwrites if it does.
Complete the code to write the string 'Hello, world!' to the file.
file.write('[1]')
The string must exactly match 'Hello, world!' including punctuation and capitalization.
Fix the error in the code to properly close the file after writing.
file.[1]()The method to close a file is close().
Fill both blanks to write 'Python' followed by a newline to the file.
file.write('[1]'[2]'\n')
Use string concatenation with '+' to add a newline character '\n' after 'Python'.
Fill all three blanks to write each word in the list to the file on separate lines.
words = ['apple', 'banana', 'cherry'] for [1] in words: file.write([2] + [3])
Use 'word' as the loop variable and write each word plus a newline '\n' to the file.
