This Python Lab 9 Lab:  Write a file copying program.  The program asks for the name of the file to copy from (source file) and the name of the file to copy to (destination file).  The program opens the source file for reading and the destination file for writing.  As the program reads each line from the source file and it writes the line to the destination file.  When every line from the source file has been written to the destination file, it close both files and print “Copy is successful.” In the sample run, “add.py” is the source file and “add-copy.py” is the destination file.  Note that both “add-copy.py” is identical to “add.py” because “add-copy.py” is a copy of “add.py”.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 6PP: (Data processing) Write a C++ program that reads the file created in Exercise 4 one record at a...
icon
Related questions
Question

This Python

Lab 9

Lab:  Write a file copying program.  The program asks for the name of the file to copy from (source file) and the name of the file to copy to (destination file).  The program opens the source file for reading and the destination file for writing.  As the program reads each line from the source file and it writes the line to the destination file.  When every line from the source file has been written to the destination file, it close both files and print “Copy is successful.”

In the sample run, “add.py” is the source file and “add-copy.py” is the destination file.  Note that both “add-copy.py” is identical to “add.py” because “add-copy.py” is a copy of “add.py”.

Sample run:

Enter file to copy from: add.py

Enter file to copy to  : add-copy.py

Copy is successful.

 

Source file: add.py

print("This program adds two numbers")

 

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

 

print(f"{a} + {b} = {a+b}")

 

Destination file: add-copy.py

print("This program adds two numbers")

 

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

 

print(f"{a} + {b} = {a+b}")

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr