Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

a file named \songs.txt\ exists and has 70 lines of data. you open the …

Question

a file named \songs.txt\ exists and has 70 lines of data. you open the file with the following line of code: afile = open(\games.txt\, \w\) you write three 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("games.txt", "w") truncates the existing file (if it exists) and starts writing from the beginning. So the original 70 - line content of "songs.txt" is not relevant as we are opening "games.txt".

Step2: Calculate number of lines

We write 3 lines to the file "games.txt". Since the file was truncated and we only added 3 lines, the number of lines in the file when we close it is 3.

Answer:

3