In Python, Write a program that reads a file containing a text (input.txt). Read
ID: 3604975 • Letter: I
Question
In Python, Write a program that reads a file containing a text (input.txt). Read each line and send it to the output file (output.txt), preceded by line numbers. If the input file is:5 pts
Mary had a little lamb
Whose fleece was white as snow.
And everywhere that Mary went,
The lamb was sure to go!
Then the program produces the output file
/* 1 */ Mary had a little lamb
/* 2 */ Whose fleece was white as snow.
/* 3 */ And everywhere that Mary went,
/* 4 */ The lamb was sure to go!
Your code with comments
A screenshot of the execution and print out of the output.txt
Explanation / Answer
ANSWER :
import os
import sys
i = 1
f = open("input.txt","r")
copy = open("output.txt","w")
for line in f:
copy.write("/*",i)
copy.write("*/")
copy.write(line)
i = i+1
f.close()
copy.close()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.