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
SSSSS [86.1K]
4 years ago
13

"Crayon Colors The file ShortColors.txt initially contains the names of all the colors in a full box of Crayola crayons. Write a

program that deletes all colors from the file whose name contains more than six characters."

Computers and Technology
1 answer:
s2008m [1.1K]4 years ago
4 0

Answer:

I am writing the Python program. Since you have not attached the ShortColors.txt file so i am taking my own text containing the names of the colors. You can use this program for your ShortColors.txt file.

infile = "ShortColors.txt"

outfile = "NewFile.txt"

f_read = open(infile)

f_write = open(outfile, "w+")

for name in f_read:

   if len(name)<=7:

       name.rstrip()

       f_write.write(name)

f_read.close()

f_write.close()

Explanation:

I will explain the program line by line.

infile = "ShortColors.txt"  creates an object named infile which is used to access and manipulate the text file ShortColors.txt. This file contains names of colors. This object will basically be used to access and read the file contents.

outfile = "NewFile.txt"  creates an object named outfile which is used to access and manipulate the text file NewFile.txt. This text file is created to contain the colors from ShortColors.txt whose name contains less than or equal to six characters. This means NewFile.txt will contain the final color names after deletion of color names containing more than six characters.

f_read = open(infile)  in this statement open() method is used to open the ShortColors.txt file. f_read is an object. Basically the text file is opened to read its contents.

f_write = open(outfile, "w+")   in this statement open() method is used to open the NewFile.txt file. f_write is an object. Basically this text file is opened in w+ mode which means write mode. This is opened in write mode because after deleting the colors the rest of the colors with less than or equal to six characters are to be written in this NewFile.txt.

for name in f_read:  this is where the main work begins to remove the colors with more than six characters. The loop reads each name from the ShortColors.txt file and here f_read object is used in order use this text file. This loop continues to read each name in the text file and executes the statements within the body of this loop.

if len(name)<=7:  this if condition in the body of for loop checks if the length of the color name is less than or equal to 7. Here each character is counted from 0 to 6 so that is why 7 is used. To check the length of every color name len() method is used which returns the length of each name.

name.rstrip()  this method rstrip() is used to remove the characters from each name whose length is greater than 6.

f_write.write(name)  now write() method is used to write the names of all the colors with less than or equal to six characters in NewFile.txt. For this purpose f_write object is used.

Here i did not remove the colors from the original file ShortColors.txt to keep all the contents of the file safe and i have used NewFile.txt to display color names after deletion of all colors whose name contains more than six characters.

After the whole process is done both the files are closes using close() method.

Attached screenshots are of the program, the ShortColors.txt and NewFile.txt.

You might be interested in
Question 1 Why should a user seek support when troubleshooting a computer problem is beyond his or her technical knowledge?​
sveticcg [70]

A user must seek support when troubleshooting a computer problem is beyond his or her technical knowledge because: <em>When the user seeks support, the computer problem is solved accordingly and further complications are avoided.</em>

Discussion:

Further computer problems may arise from a computer problem. As such, when a user finds it difficult to troubleshoot a computer problem, the user should seek support since the computer problem is beyond his or her technical knowledge

Read more on troubleshooting:

brainly.com/question/18315517

6 0
3 years ago
Careers on the largest declining industries list will see an increase in the number of employees in their workforce.
IrinaK [193]

The answer is False.

The word "declining" means going down. So, in this case, the employees would go down or leave.

7 0
3 years ago
You are a very small company that sells healthcare insurance plans. You estimate that the breach of your customer database will
lozanna [386]

Answer:

C. Accept the risk

Explanation:

The first option is close but might not be suitable for a small company considering it's cost.

The second option which is to spend fifty thousand dollars per year on a data loss prevention solution is projected to cost you more than the risk.

The third option isn't specific and lacks a course of action.

6 0
3 years ago
You need to add cells c3 and c7, and multiply c3 by c6. based on the order of operations, what would you do
Julli [10]
Multiply first, and then add.
6 0
4 years ago
Read 2 more answers
The company where Derek works has tasked him with setting up and securing a SOHO router. He wants to make sure the wireless netw
Bogdan [553]

Answer:

Change default username and password.

Explanation:

The corporation under which Derek works has assigned him an assignment of establishing and safeguarding a SOHO router. He intends to ensure that maybe the wireless connection is protected and no further unauthorized person would connect the device to the router. So, the first task is to simply change the username and password that the wifi routers will be secured.

So, the following answer is correct about the given scenario.

6 0
4 years ago
Other questions:
  • How many megabytes of data can a factory made audio cd hold?
    13·1 answer
  • The drone intercepts at 1256 hour. what time do they plane to take control of the drone
    11·1 answer
  • Monetary Policy can be either Expansionary or Contractionary. Which of the following actions classify as Expansionary Monetary P
    7·2 answers
  • SecOps focuses on integrating the need for the development team to provide iterative and rapid improvements to system functional
    11·1 answer
  • CHKDSK is a system utility that is commonly found in Windows. What is CHKDSK? Use the Internet to research and write about CHKDS
    15·2 answers
  • Design a Ship class with the following members:
    13·1 answer
  • Why is it important to try to make financial decisions without emotions.
    12·2 answers
  • Which steps do you follow to create a graph?
    5·2 answers
  • ¿en minimo cuantos computadores se puede construir una red,y en maximos en cuanto y que se necesita para que este en la red?​
    14·1 answer
  • Not every design choice in your game interface requires having a thought process behind it.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!