QUESTION IMAGE
Question
a file named \cats.txt\ exists and has 50 lines of data. you open the file with the following line of code. afile = open(\games.txt\, \w\) you write five lines to the file in the program. how many lines are in the file when you close your file?
Step1: Understand file - opening mode
The "w" mode in open function truncates the existing file (if it exists) and starts writing from the beginning. So the original content of "games.txt" (if any) is deleted.
Step2: Calculate number of lines
Since we start with an empty file (because of "w" mode) and write 5 lines, the number of lines in the file when we close it is 5.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
5