1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alchen [17]
3 years ago
12

Create a file with a 20 lines of text and name it "lines.txt". Write a program to read this a file "lines.txt" and write the tex

t to a new file, "numbered_lines.txt", that will also have line numbers at the beginning of each line.

Computers and Technology
1 answer:
Nezavi [6.7K]3 years ago
6 0

Answer:

I am writing a Python program:

read_file = open("lines.txt", 'r')  #opens file in read mode

#read_file is a file object

lineNo = 1  #assigns line number to each line

write_file = open("numbered_lines.txt", 'w')# opens file in write mode

#write_file is a file object

for i in read_file:  # loop on read file

   write_file.write(str(lineNo) + " " + i)

#writes line number on start of each line in write file  

   lineNo += 1  increments line number

read_file.close()  # closes file to read

write_file.close() # closes file to write on

Explanation:    

This program first opens the file name lines.txt to read the contents of the file using open() function. Then the new file numbered_lines.txt is opened in write mode to write the contents on it. Then the for loop moves through each line of lines.txt and adds the line numbers to each line of the numbered_lines.txt .The line number lineNo increments by 1 at each iteration so that each line of the file gets a number from 1 to 20. At the end both the files are closed using close() function. The screen shots of program and both the files is attached.

You might be interested in
Which year was the Apple 2 released? <br>A) 1979 <br>B). 1973 <br>C). 1980 <br>D). 1977​
sesenic [268]

Answer:

1977

Explanation:

Apple 2 was released in April 19th 1977

6 0
3 years ago
Read 2 more answers
Whats difference between DCE AND DTE serial interface
harina [27]

DCE stands for data circuit-terminating, data communications, or data carrier equipment - this is a modem or more generally, a line adapter.

DTE stands for data terminal equipment which generally is a terminal or a computer.

Basically, these two are the different ends of a serial line.

7 0
3 years ago
Exercise #3: Write a c++ program that reads, from a file called numbers.in, up to 10 numbers, counts and adds the positive value
Gre4nikov [31]

I don't know

Thanks for the points

3 0
3 years ago
Read 2 more answers
Modify the FitnessTracker class, created in Chapter 4 Programming Exercise 3AB, so that the default constructor calls the three-
Ivenika [448]

Answer:

Is this coding?

Explanation:

5 0
3 years ago
What's the best way to change the font size of all your notes pages at once?
defon
On which os? mac os windows linux?
7 0
3 years ago
Other questions:
  • The part you should check first when you are servicing a sparking universal motor is the A. commutator. B. armature. C. brushes.
    9·1 answer
  • What feature is available to add a suggestion in the margin of someone else's document?
    7·1 answer
  • What is an important step to take before entering your first data into your database?
    10·2 answers
  • Identify the characteristics of logic problems.select all that apply
    5·1 answer
  • Write a C++ Win32 Console Application that will use nested for loops to generate a multiplication table from 1 x 1 to 10 x 10. U
    12·1 answer
  • What are the three types of mergers?
    8·1 answer
  • Data owners ensure that only the access that is needed to perform day-to-day operations is granted and that duties are separated
    10·1 answer
  • A technology called ______
    11·1 answer
  • Which command must you use at the command prompt to determine the names of the network interfaces (including the isatap interfac
    13·1 answer
  • bookmark question for later what database did zach choose? microsoft excel microsoft access db2 oracle
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!