Complete the code so it runs in Python: Write a program that concatenates the co
ID: 3674734 • Letter: C
Question
Complete the code so it runs in Python:
Write a program that concatenates the contents of several files into one file. For example, $ python catfiles.py chapter1.txt chapter2.txt chapter3.txt book.txt makes a long file book.txt that contains the contents of the files chapter1.txt, chapter2.txt, and chapter3.txt. The target file is always the last file specified on the command line. The following code demonstrates simple command line argument passing:
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
def get_arguments():
char arg[4],argv;
List_arguments=[book.txt,chapter1.txt, chapter2.txt,chapter3.txt]
for arg in argv:
arg=raw_input("Enter the arguments:")
List_arguments.append(arg)
print "book.txt contains chapter1.txt,chapter2.txt,chapter3.txt"
def catfile(chapter1.txt,book.txt)
book.txt=open(book.txt,"a")
with open (chapter1,"r") as file
for line in file
book.txt.write(line)
file.close()
book.txt.close()
def catfile(chapter2.txt,book.txt)
book.txt=open(book.txt,"a")
with open(chapter2.txt,"r") as file
for line in file
book.txt.write(line)
file.close()
book.txt.close()
def catfile(chapter3.txt,book.txt)
book.txt=open(book.txt,"a")
with open(chapter3.txt,"r") as file
for line in file
book.txt.write(line)
file.close()
book.txt.close()
def catfile(arguments_list, book.txt):
for i in rang(1,len(arguments_list)-1):
i=raw_input("Enter the value of i:")
catfile(arguments_list[i], book.txt)
void main():
arguments=get_arguments()
book.txt=arguments(-1)
catfiles(arguments,book.txt)
if(book.txt=chapter1.txt_main()):
def catfile(chapter1.txt,book.txt)
elif(book.txt=chapter2.txt_main()):
def catfile(chapter2.txt,book.txt)
else
def catfile(chapter3.txt,book.txt)