Write a function concatenate_files(filename1, filename2,new_filename) that conca
ID: 3587821 • Letter: W
Question
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 filename2follows the text from filename1. The concatenated text is written to a new file with the name given by new_filename. Your function 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.
My incomplete CODING:
def concatenate_files(filename1, filename2, new_filename):
string1 = open(filename1, 'r').read()
string2 = open(filename2, 'r').read()
strings = string1, string2
f = open(new_filename, 'a')
for string in strings:
f.write(string, 'a')
string += 1
f.close()
Please correct my code according to this question and tell me which steps i did wrongly, please :) thank you !
Explanation / Answer
def concatenate_files(filename1, filename2, new_filename):
string1 = open(filename1, 'r').read()
string2 = open(filename2, 'r').read()
strings = string1, string2
f = open(new_filename, 'a')
for string in strings:
f.write(string) #it takes only one argument
#string += 1 #no need of this line
f.close()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.