Answer to Question #231131 in Python for Rachna Pal

Question #231131

Write a Python program which allows you to extract the content of a file from the 

3rd line to the 5th line and save it in another file.


1
Expert's answer
2021-09-05T00:32:46-0400


file1 = 'input.txt' 
infile = open(file1, 'r')
file2 = 'output.txt' 
outfile = open(file2, 'w')


count=0;
for line in infile:
    count+=1
    if(count>=3 and count<=5):
        outfile.write(line)


infile.close()
outfile.close()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS