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
Tema [17]
4 years ago
13

#Write a function called one_dimensional_booleans.

Computers and Technology
1 answer:
deff fn [24]4 years ago
5 0

Answer:

def one_dimensional_booleans(bool_list, use_and):

   

   is_all_true = True

   is_one_true = False

   

   if use_and:

       for b in bool_list:

           if b == False:

               is_all_true = False

               break

   

       if is_all_true:

           return True

       else:

           return False

   

   else:

       for b in bool_list:

           if b == True:

               is_one_true = True

               break

   

       if is_one_true:

           return True

       else:

           return False

Explanation:

Create a function named one_dimensional_booleans that takes two parameters, bool_list and use_and

Inside the function:

Set is_all_true as True and is_one_true as False. These will be used to check the list

If use_and is True, check each item in the bool_list. If one item is False, set the is_all_true as False and stop the loop. This implies that the list contains a False value. Then check the is_all_true. If it is True, return True. Otherwise, return False.

If use_and is False, check each item in the bool_list. If one item is True, set the is_one_true as True and stop the loop. This implies that the list contains a True value. Then check the is_one_true. If it is True, return True. Otherwise, return False.

You might be interested in
Write a short note on pen drive​
lbvjy [14]

Answer:

They are called "flash drive" because they use flash memory to store files. Other common names for a flash drive include pendrive, thumbdrive or simply USB. USB flash drives have some advantages over other portable storage devices.A pen drive is a portable Universal Serial Bus (USB) flash memory device for storing and transferring audio, video, and data files from a computer. A pen drive usually has a large storage capacity and provides quick data transfers.

8 0
3 years ago
Create and apply a css class named bigblue, which selects a large, blue-colored font.
a_sh-v [17]
.bigblue {
font-size: xx-large;
color: blue;
}
3 0
3 years ago
Please select the word from the list that best fits the definition
PilotLPTM [1.2K]

the best word that fits the definition is absolute.

6 0
3 years ago
Read 2 more answers
Which type of data is shown below?<br> apple, 0.85<br> banana, 0.90<br> peach, 1.50
d1i1m1o1n [39]

Answer:

dictionary data

Explanation:

data = {"apple" : 0.85, "banana" : 0.90, "peach": 1.50}

4 0
3 years ago
"Crayon Colors The file ShortColors.txt initially contains the names of all the colors in a full box of Crayola crayons. Write a
s2008m [1.1K]

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.

4 0
4 years ago
Other questions:
  • Create a class in JobApplicant.java that holds data about a job applicant. Include a name, a phone number, and four Boolean fiel
    13·1 answer
  • What should you keep in mind when typing a message on the Internet?use as many A.acronyms as it saves space
    7·1 answer
  • how do i create an advanced search using the search criteria in the range K2:S3 and the inventory data where the results will be
    8·1 answer
  • What happens when the data in an investigation does not support the original hypothesis? The scientist gives up and starts an in
    10·2 answers
  • You are an administrator for the Contoso Corporation. You have client software that receives its configuration from a shared fol
    10·1 answer
  • The three main types of banks (Large Traditional, Credit Union, Online or Online-Only) have many tradeoffs with respect to techn
    15·2 answers
  • Type the correct answer in the box. Spell all words correctly.
    12·1 answer
  • According to what theory did the universe expand explosively into existence 13.7 billion years ago?
    13·2 answers
  • What should you do first when designing a program?
    5·2 answers
  • Assign total_owls with the sum of num_owls_A and num_owls_B.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!