(Solved):A file named data1.txt contains an unknown number of lines, each consisting of a single integer. Write Python code that creates a file named data2.txt and copies all the lines of data1.txt to data2… View Answer…

 

Question

A file named data1.txt contains an unknown number of lines, each consisting of a single integer. Write Python code that creates a file named data2.txt and copies all the lines of data1.txt to data2.txt.

 

EXPERT ANSWER

Second line of code opens and/or creates a data2.txt file for writing. Fifth line is a standard way of opening a file for reading or writing.

Open method takes two arguments, namely 1) file name.

Scroll to top