Question

Instructions Forum Tutoring Problem program. Write a function concatenate_files(filename1, filename2, new filename) that conc
Concatenate Files program.py part1.txt part2.txt 1 Either the well was very deep, or she fell very slowly, for 2 she had plen

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 that the text from the file named by argument filename 2 follows the text from filename1. The concatenated text is written to a new file with the name given by new_filename. Your function O must not return anything. We have provided sample input files named part1.txt and part2.txt containing a portion of the text from the novel Alice in Wonderland to test your function. W14 Closing Files Do not forget to close your files! O 9 Submissions M1 Autosaved Output
Concatenate Files program.py part1.txt part2.txt 1 Either the well was very deep, or she fell very slowly, for 2 she had plenty of time as she went down to 3 Look about her and to wonder what was going to happen next. 49 Suhmissions sou
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
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...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT