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
What line of business (L'Oréa)?​
tatiyna

Answer:

skin care personal care

Explanation:

just search up what line of business in l orea

6 0
3 years ago
Read 2 more answers
How to burn mp3 on dvd
ki77a [65]
Look up on google a software that can do it for you. Doing it through a pre-made software is about the only way to do it most computers won't allow you to.

7 0
4 years ago
Read 2 more answers
The point at coordinates (2, -18) is in what direction from the origin?
laila [671]
On a graph, move 2 spaces to the right and from there move 18 spaces down. Now, where you've ended, make a dot. The distance fro the origin is -2/18 (as a fraction).
4 0
4 years ago
Who's better Kapkan or Tachanka?
navik [9.2K]
If you want fun operator, get chanka, if you want good operator, get kapkan it also depends if depends you are a stationary man who likes big guns or a mobile man who likes traps
4 0
4 years ago
A flashlight bulb uses 2.4 W of power when the current in the bulb is 0.8 A. What is the voltage difference?
Alinara [238K]

Answer:

3 Volts.

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • What is a common source of connection problems with ethernets?
    9·2 answers
  • What tool enables you to easily delete, add, or resize filesystems without regard to their physical locations on a hard disk?
    13·1 answer
  • Mercury Technical Solutions has been using SSL in a business-to-business environment for a number of years. Despite the fact tha
    5·1 answer
  • Seth is researching new developments in cancer treatments. Which suggestion would be most beneficial to making sure his search r
    14·1 answer
  • For what kind of shot is a fisheye lens most appropriate?
    8·1 answer
  • The Windows Remote Desktop Web connection that allows users to connect to a work or home computer and access files is considered
    7·2 answers
  • Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by ea
    12·1 answer
  • From Blown to Bits why is it important to know what children are doing on the Web Tonight?
    7·1 answer
  • Letter only ^_____^!
    8·1 answer
  • I need major help. Word processing
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!