Consider the following Python code :
import shutil; #importing the module for concatenating
purpose.
print("Please enter 'E' for exit.");
filename1 = input("Please enter first file name to concatenate: ");
#getting first file to concatenate.
if filename1 == 'E': #checking if user wants to exit or not.
exit(); #used for exit the program
else:
filename2 = input("Please enter second file name to concatenate:
"); #getting second file to concatenate.
filename3 = input("Create a new file to concatenate content of two
files inside this file: ");
print();
print("concatenating the content of two file in",filename3);
with open(filename3, "wb") as wfd: #code for concatenating two
files in third file.
for f in [filename1, filename2]:
with open(f, "rb") as fd:
shutil.copyfileobj(fd, wfd, 1024*1024*10);
print("\nContent concatenated successfully.!");
print("Want to see ? (yes/N): "); #used for checking correct
result.
check = input();
if check == 'N':
exit();
else:
print();
c = open(filename3, "r");
print(c.read());
c.close();
Consider that the filename1 file contains "Hello" and the filename2
file contains"World".
Output of the above code will be : HelloWorld
The above python code will concatenate the content of filename1 and filename2 into filename3.The above python code if properly working and is concatenating the contents properly.
the language is python Instructions Forum Tutoring Problem program. Write a function concatenate_files(filename1, filename2, new filename) that concatenates the text from two source files such...