Answer:
- texts = ""
-
- with open("text.txt") as file:
- texts = file.readlines()
-
- with open("output.txt", "w")as file:
- i = 1
- for s in texts:
- file.write("/*" + str(i) + "*/" + s)
- i += 1
Step-by-step explanation:
The solution code is written in Python 3.
Firstly, create a variable texts to hold the contents read from the text file. Next, open the file stream and use readlines method to read the contents from text.txt and assign it to variable texts (Line 3-4).
Next, open another file stream but for this time the file stream is used to output each row of the texts preceded by line number (Line 6 -10).