Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

a file named \cats.txt\ exists and has 50 lines of data. you open the f…

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?

Explanation:

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.

Answer:

5