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
lukranit [14]
3 years ago
14

Define a function allEqual of type ''a list -> bool that will return true will all element in the input list are all equal, f

alse otherwise. If the input list is empty or is a singleton list, the function should return true. For example,
Computers and Technology
1 answer:
ser-zykov [4K]3 years ago
3 0

Answer:

Follows are the code to this question:

def allEqual(l):#defining a method allEqual that accepts a parameter  

   if len(l)==0:#defining if block that check list length equal to 0

       return True#return true value

   x=set(l) #defining x variable that set of given list

   if len(x)!=1: #defining if that check x is not equal to 1  

       return False#return False

   return True#return True

print(allEqual([]))#Use print method to call method and print value

print(allEqual(["aa"]))#Use print method to call method and print value  

print(allEqual(["aa", "aa", "aa"]))#Use print method to call method and print value  

print(allEqual(["aa", "aa", "ab"]))#Use print method to call method and print value

print(allEqual([1,1,3, 1]))#Use print method to call method and print value

Output:

True

True

True

False

False

Explanation:

In the above-given code a method "allEqual" is defined that accept and a list in its parameter and inside the method a conditional statement is used that can be defined as follows:

In if block, it checks the length of the list which is equal to 0, it will return 0.

In the next step, an "x" variable is declared, that uses the set method to hold list value and use if block to check length not equal to 1 and return false, or method returns a value that is equal to true.

You might be interested in
Zoey has brought her computer in for servicing. When she dropped off her computer, she mentioned that her computer will sometime
galina1969 [7]

Answer:

Option (B) Overheated CPU

Explanation:

  • The above problems mentioned are due to the problem with the CPU.
  • Overheated CPU can result into freezing the computer and unexpected rebooting.
  • CPU stands for Central Processing Unit and is responsible for all the instabilities in the hardware parts of the computer.
  • So, option (b) is true.
  • A Network Card is responsible for connecting the computer to the internet. It also has other names like Ethernet Card. A bad Network Card results in problems with the internet and network connections but not the above problems. So, option (A) is false.
  • UPS is Uninterrupted Power Supply. It is an external power device to provide the power supply to the computers in case of emergencies to not shut down the computer instantaneously. The above problems are not likely to be the caused by the failed UPS. So, option (C) is false.
  • Drive is a hardware device to store information. It can be removable drive (optical drives like CDs, DVDs ) or non removable like ( Hard Disk Drive ). A failed drive results in problems with the storing information. The above problems are not associated with it. So, option (D) is also false.
6 0
3 years ago
Read 2 more answers
The design or organization of a text is it’s
Zarrin [17]
The design or organization of a text is it’s C. Format
8 0
3 years ago
Read 2 more answers
List 5 items you should keep in mind when developing an app:
Mrac [35]

Answer:

  1. Agree on aims concerning the application.
  2. Read your end users.
  3. Take your IT partners toward the conversations in the beginning.
  4. Program for various announcements.
  5. Choose the technology which you know and will be able to continue.

Explanation:

You should always keep the above five points while developing an app. You should keep your goals in mind that what kind of app you are going to develop and you are taking surveys from end users that what they want after some time in different cycles. Your team should discuss your project time by time about the progress of an app. Your project should be a long term and should almost cover all kind of users.



6 0
3 years ago
G=D+(A+C^2)*E/(D+B)^3 Rewrite the above formula in terms of doing concurrent processing using cobegin and coend to identify thos
jeka57 [31]

Answer:

G=D+(A+C^2)*E/(D+B)^3

p1:C^2

p2:(D+B)^3

p3:A+p1

p4:E/p2

p5: D+p3+p4

COBEGIN

P1(p1,p2)

COEND

COBEGIN

P2(p3,p4)

COEND

execute p5

Explanation:

P1, P2 are parallel processes as they are independent of each other. And p5 together with P1, P2 forms the serial list of processes, and these must be executed serially.  And we need to run as mentioned above concurrent processes under cobegin and coend. Hence the above is the required list of processes and how they are processed. Concurrent processes are listed under cobegin and coend.

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:
  • When performing actions between your computer and one that is infected with a virus which of the following offers no risk becomi
    5·1 answer
  • All of these are required categories on a safety data sheet except
    14·2 answers
  • How can my computer catch a virus?
    13·1 answer
  • Physical security controls traditionally include obstacles, alarms, lights, guards, cameras, and responders that produce a(n) __
    15·1 answer
  • The appropriate length for an e-mail is about half the amount of text that will fit on an 8 1/2' by 11' page.
    11·2 answers
  • Effective character encoding requires:
    8·1 answer
  • Write the DML statement to query the database for the following: Output the fname, lname, total_amount_owed of the student with
    5·1 answer
  • A U.S. social security number consists of a string of 9 digits, such as "444422333". Assume that input consists of a sequence of
    6·2 answers
  • Type the correct answer in the box Spell the word correctly.
    7·1 answer
  • List how much hard disk capacity you recommend, and write a sentence explaining why.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!