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
Phoebe has to give a presentation about recycling. Where should she look while presenting?
Naddika [18.5K]
Well, I think that maybe the answer is B or C. She shouldn't only look at her presentation while she is presenting it, that doesn't look professional, and you want to look at the people you are talking to.
6 0
3 years ago
Read 2 more answers
You have recently been called to troubleshoot network connectivity problems at a user's workstation. You have found that the net
Verdich [7]

Answer:

The answer is "Pass the cable into the ceiling instead of over the floor".

Explanation:

Network access explains the complex process of link different parts of the network with each other, e.g. while using switches, routers, and access points, and whether, that system works.

  • To replace the cable with a pair cable graded in plenum, covered, twisted.
  • We use the cable to pass through the ceiling rather than through the concrete, eliminating the issue and stopping it from occurring again.
3 0
4 years ago
A programmer tests the procedure with various inputs and finds multiple cases where it does not produce the expected output. whi
AnnZ [28]

Answer:

longestWord(["frog", "seagull", "mermaid"])

longestWord(["crown", "diamond", "castle"])

Brainlist pls!

6 0
2 years ago
Output values below an amount Write a program that first gets a list of integers from input. The input begins with an integer in
Katarina [22]

The program that first gets a list of integers from input, gets the last value from the input, which indicates a threshold, and outputs all integers less than or equal to that last threshold value is:

import java.util.Scanner;

public class LabProgram {

 /* Define your methods here */

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int[] userValues = new int[20];

int upperThreshold;

int numVals;

numVals = scnr.nextInt();

GetUserValues(userValues, numVals, scnr);

upperThreshold = scnr.nextInt();

OutputIntsLessThanOrEqualToThreshold(userValues, numVals, upperThreshold);

}

}

Read more about java programming here:

brainly.com/question/26952414

#SPJ1

6 0
2 years ago
Question 5.5. A computer network is BEST described as two or more computers that are
Elden [556K]
I think it is compatible im not sure hope this helps
8 0
4 years ago
Other questions:
  • What tab must you click on to view any previously read messages from instructors in the message center?
    14·2 answers
  • Google Slides saves your work to Google Drive. PowerPoint has the option to save to OneDrive. Both of these solutions are in the
    9·1 answer
  • The option to add the date and time to a document is located in the
    9·2 answers
  • Which type of network topology has a central networking device which manages the network and acts as a communications conduit fo
    7·1 answer
  • 4. The Internet may best be compared to a/an A. series of colored lights. B. loud truck motor. C. enormous skyscraper. D. large
    6·1 answer
  • What is Java Script?
    13·1 answer
  • Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. End with a n
    7·2 answers
  • DEF is a small consulting firm with ten on-site employees and 10 to 12 part-time (off-site) software consultants. Currently, the
    5·1 answer
  • PLEASE HELP! :)
    14·1 answer
  • What is output by the following line of code?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!