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.
# 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)
Comments
Leave a comment