Q. Write a program that appends the contents of one file to another. Have the program take the filenames from the user.


You can understand by Watching video :-



Answer :-

file1 = input("Enter the name of file which you want to append : ")
file2 = input("Enter the name of original file : ")

old =  open( file2 , "r" )
new = open( file1 , "a" )

data = old.read()
new.write( "\n" + data)

print("Program run successfully ")

old.close()
new.close()

Story.txt Contains :-

A boy is playing there.
There is a playground.
An aeroplane is in the sky.
Alphabets & numbers are allowed in password.
This is Path Walla Website.

Initially Path Walla.txt Contains :-

Python is Best Pragamming Language in The whole World

Output :-

Enter the name of file which you want to append : Path Walla.txt
Enter the name of original file : story.txt
Program run successfully

>>>

Finally Path Walla.txt Contains :-

Python is Best Pragamming Language in The whole World

A boy is playing there.
There is a playground.
An aeroplane is in the sky.
Alphabets & numbers are allowed in password.
This is Path Walla Website.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post