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
An intentional action designed to prevent legitimate users from making use of a computer service is called
MatroZZZ [7]
Denial of Service Attack. If multiple machines are involved, it's a Distributed Denial of Service Attack.
4 0
4 years ago
What’s a device that uses the measurement of a BIT?
Akimi4 [234]
A computer uses BIT. Hope this helps
5 0
3 years ago
Janeal spends her day looking at the stock and bond markets and evaluating how the portfolios of the businesses she serves will
pychu [463]

Answer:

ur answer good sir will be : financial analyst

and a brainliest will be good to thnx

4 0
4 years ago
Ano ang bunga ng pagsunod sa tamang konsiyensiya?
gladu [14]

Answer:

A.

Explanation:

mapalaganap ang kabutihan

8 0
3 years ago
Read 2 more answers
Building relationships during your career exploration is called
miskamm [114]
Building relationships during your career exploration is called Networking.  Networking doesn't necessarily guarantee you a job, but when you're in career exploration phase, building relationships with various people may expose you to various kind of opportunities that could benefit your career paths
7 0
4 years ago
Other questions:
  • The first electronic networking technology widely used in the United States was the:
    6·1 answer
  • Do you think social media should affect presidential elections
    6·2 answers
  • How can cultural hearths be described
    5·1 answer
  • Markup is best defined as
    11·1 answer
  • The bluecross blueshield federal employee program (fep) is a(n) __________ health benefits program established by an act of cong
    8·1 answer
  • the part of the computer that contains the brain , or central processing unit , is also known the what ?
    12·1 answer
  • What type of Microsoft Server serves as an email server?
    7·2 answers
  • The _____ method randomly rearranges the items in the list provided in the parentheses.
    5·2 answers
  • The first photo in the collage is what I should make a copy of, anyone has any knowledge on how to add the numbers apart of the
    5·1 answer
  • Problem 8 - Recursive Divisible by 3 and 5 Complete the divBy3And5 function which accepts a list of integers. The function shoul
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!