This is phython not Java 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}")
This is phython not Java
Lab: Write a file copying
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}") |
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images