Question 4
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
import os, tempfile
os.chdir(tempfile.mkdtemp())
total = 450
with open("total.txt", "w") as f:
f.write(total)
- A It writes 450
- B ValueError
- C TypeError: write() needs a str; write str(total) or an f-string Correct
- D It writes nothing
Correct Answer: Option C
Python reports "write() argument must be str, not int".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!