Problem Statement
Which file mode creates a new file and raises an error if the file already exists?
Explanation
Mode x is exclusive creation. It succeeds only if the file does not exist. This is useful when you want to avoid accidental overwrites.
Mode w truncates existing files. Mode a appends if the file exists, or creates it if not. Mode r+ reads and writes without truncation.
Code Solution
SolutionRead Only
with open('report.txt', 'x', encoding='utf-8') as f:
f.write('first run only')