Answer to Question #283350 in Python for ramk

Question #283350

Design a python program that merges two files and write the results to new file (THREE.txt). The merge operation should take place line by line. The first line of the merged file should contain the first line of TWO.txt and the second line of the merged file should contain the first line of the ONE.txt.  

For Example:- The content of ONE.txt and TWO.txt are input and the content of THREE.txt is the output.  

Input:- 

Python Language is old Programming language!!! 

Which Language is Old Programming Language? 

Output: 

Which Language is Old Programming Language?  

Python Language is old Programming language!!! 


case=1 

input= This is same as C Programming language used to do more complex problem. 

Usually a file is kept on a permanent storage media, e.g. a hard drive disk. 

output= Usually a file is kept on a permanent storage media, e.g. a hard drive disk. 

This is same as C Programming language used to do more complex problem. 




1
Expert's answer
2021-12-29T02:20:00-0500
# Python program to
# demonstrate merging
# of two files


data = data2 = ""


# Reading data from file1
with open('file1.txt') as fp:
	data = fp.read()


# Reading data from file2
with open('file2.txt') as fp:
	data2 = fp.read()


# Merging 2 files
# To add the data of file2
# from next line
data += "\n"
data += data2


with open ('file3.txt', 'w') as fp:
	fp.write(data)

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