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
U GET BRAINLIEST HELP PLZ
Art [367]
BOTH OF THEM ARE C : )
3 0
3 years ago
What is windows powershell? I downloaded a fake video game on my PC.(It was an accident) Now, powershell is bugging me. Is it a
IrinaVladis [17]

Answer:

The PowerShell is a kind of shell framework, which was being developed by Microsoft for covering various administrative tasks like the configuration automation and management of certain repetitive jobs. And the term 'PowerShell' does refer to both of these- and its the shell applied for executing commands, and scripting language.

And yes, you have been infected by the virus. You need to run the antivirus immediately.

Explanation:

Please check the answer section.

5 0
4 years ago
Read 2 more answers
Which risk management framework does the organization of standardization publish
olga2289 [7]

Answer:

ISO 31000:2009 publishes principles and generic guidelines on risk management.

Explanation:

ISO 31000:2009 can be applied to any public, private or community company, organization, society or individual. Hence, ISO 31000:2009 is not particular to either business or area.

ISO 31000:2009 can be implemented during the period of an industry and to a broad variety of actions, including policies and judgments, guidance, methods, functions, plans, goods, services, and assets.

ISO 31000:2009 can be implemented to any type of danger, whatever its kind, whether possessing positive or negative outgrowths.

3 0
4 years ago
What is the name for the warmth or coolness of white light?
Arturiano [62]

Answer:

white balance is the correct answer

4 0
3 years ago
Write the definition of a function isSenior, that receives an integer parameter and returns true if the parameter's value is gre
ohaa [14]

Answer:

The function definition for this question can be given as:

Function Definition:

bool isSenior(int x )  //function

{  

//function body Or function definition.

//conditional statement

//if statement

if (x >=65)  

{

return true;   //return value true.

}

else  //else statement

{

return false;    //return value false.

}

}

Explanation:

In the above function definition firstly we define a function that isSenior. This function return Boolean value that is true or false in this function we pass the value as the parameter in that function we use the if statement that check the pass value is greater then equal to 65. If the condition is true it return true.else it will return false.

6 0
3 years ago
Other questions:
  • PLEASE HELP YOU GUYS
    7·2 answers
  • What is the Difference between CUI and GUI
    14·2 answers
  • ________ is a type of attack in which the attacker takes control of a session between two machines and masquerades as one of the
    5·1 answer
  • How does kinetic energy affect the stopping distance of a small vehicle compared to a large vehicle?
    14·2 answers
  • Answer ASAP and I'll give brainliest.
    10·2 answers
  • Identify one technology tool used for work​
    7·1 answer
  • Consider the following class, which models a bank account. The deposit method is intended to update the account balance by a giv
    8·1 answer
  • What facilitates the automation and management of business processes and controls the movement of work through the business proc
    9·1 answer
  • How exactly do you find the circumference by using C++ Programming? I really need a specific answer.
    14·1 answer
  • What kind of company would hire an Information Support and Service employee?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!