Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote