Home » All Blogs » Python » Python assignments » M.Sc Computer Application » M.Sc Python Programming Assignment 27
M.Sc Python Programming Assignments
Assignment 27
Question:
Write a Python program to copy the contents of a file to another file
Code:
def copy_file(source_file, destination_file):
with open(source_file, 'r') as source:
with open(destination_file, 'w') as destination:
for line in source:
destination.write(line)
print("File copied successfully!")
# Example usage
source_file = input("Enter the source file name: ")
destination_file = input("Enter the destination file name: ")
copy_file(source_file, destination_file)
Output:
Enter the source file name: goku
Enter the destination file name: vegeta
File copied successfully!