answer.
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
Elena L
18 days ago
11

This assignment is based on Exercise 8.4 from your textbook. Each of the following Python functions is supposed to check whether

its argument has any lowercase letters.
For each function, describe what it actually does when called with a string argument. If it does not correctly check for lowercase letters, give an example argument that produces incorrect results, and describe why the result is incorrect.

# 1

def any_lowercase1(s):
for c in s:
if c.islower():
return True
else:
return False


# 2

def any_lowercase2(s):
for c in s:
if 'c'.islower():
return 'True'
else:
return 'False'


# 3

def any_lowercase3(s):
for c in s:
flag = c.islower()
return flag


# 4

def any_lowercase4(s):
flag = False
for c in s:
flag = flag or c.islower()
return flag


# 5

def any_lowercase5(s):
for c in s:
if not c.islower():
return False
return True
Computers and Technology
1 answer:
Amiraneli [1K]18 days ago
4 0
#1 is incorrect since it stops and returns false if the first character isn't lowercase, disregarding the other characters. To correct this, you can eliminate the else: clause and place the return False statement outside the loop. This way is more efficient; the function can return true as soon as it encounters a lowercase letter. It only has to loop to the end if no lowercase letters are found.
You might be interested in
Choose the person responsible for each innovation.
zubka84 [1067]

Response:

John Blankenbaker

Reasoning:

5 0
1 month ago
Explain how abstraction is used in a GPS system
ivann1987 [1066]

Answer

Abstraction in GPS technology allows the system to use clearly defined interfaces while enabling the integration of additional, more complex functionalities.

Explanation

The GPS system employs abstraction to organize layers of complexity for user interaction. It connects satellite-based positioning and timing systems to enable a radio receiver to acquire signals across four dimensions—latitude, longitude, altitude, and time—after synchronizing this data.


7 0
2 months ago
Read 2 more answers
Write a Python3 program to check if 3 user entered points on the coordinate plane creates a triangle or not. Your program needs
Rzqust [1037]

Answer:

tryagain = "Y"

while tryagain.upper() == "Y":

    x1 = int(input("x1: "))

    y1 = int(input("y1: "))

    x2 = int(input("x2: "))

    y2 = int(input("y2: "))

    x3 = int(input("x3: "))

    y3 = int(input("y3: "))

    area = abs(x1 *(y2 - y3) + x2 * (y1 - y3) + x3 * (y1 - y2))

    if area > 0:

         print("Inputs form a triangle")

    else:

         print("Inputs do not form a triangle")

    tryagain = input("Press Y/y to try again: ")

Explanation:

To check for this, we will simply compute the area of the triangle given that inputs are on a coordinate plane i.e. (x,y).

An area greater than 0 means it's a triangle

Conversely, if not, it's not a triangle.

This line starts the loop with variable tryagain set to Y

tryagain = "Y"

while tryagain.upper() == "Y":

Following lines retrieve the triangle's coordinates     x1 = int(input("x1: "))

    y1 = int(input("y1: "))

    x2 = int(input("x2: "))

    y2 = int(input("y2: "))

    x3 = int(input("x3: "))

    y3 = int(input("y3: "))

Now, this computes the area

    area = abs(x1 *(y2 - y3) + x2 * (y1 - y3) + x3 * (y1 - y2))

Finally, this checks the condition mentioned above.

    if area > 0:

         print("Inputs form a triangle") This message appears if the condition is true

    else:

         print("Inputs do not form a triangle") This is printed if the condition is not met

    tryagain = input("Press Y/y to try again: ") It prompts the user to input new values

4 0
20 days ago
Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
maria [1035]

Answer:

To prevent nested conditionals, one can utilize logical expressions like the AND operator.

A recommended approach is creating an interface class with a method designed for a shared function. This design approach is known as the strategy design pattern. The conditional statements can be consolidated into this method. Subsequently, each class can implement this interface and invoke that shared method as needed by constructing instances of subclasses and calling the common method for those objects. This illustrates polymorphism.

Explanation:

Nested conditionals occur when if or else if statements are placed within another condition. For instance:

if( condition1) {

//runs when condition1 is true

  if(condition2) {

//runs when both condition1 and condition2 are true

  }  else if(condition3) {

 //when condition1 is true and condition3 is also true

} else {

 //condition1 is true but neither condition2 nor conditions3 are satisfied

}  }

Excessive nested conditionals can complicate the program, rendering it hard to read or comprehend, particularly if there's improper indentation. Debugging also becomes challenging when there are numerous nested statements.

Thus, several strategies can be adopted to eliminate nested conditionals, such as utilizing a switch statement.

For instance, I’ll present an example of the strategies discussed earlier:

Logical Expressions Usage:

A method to avoid nested conditionals is by employing logical expressions with logical operators like the AND operator. The previous nested conditionals can be reframed as:

if(condition1 && condition2){ //only runs when both condition1 and condition2 are true

} else if(condition1 && condition3) {

executes only if both condition1 and condition3 are true

} else if(condition1 ){

//condition1 is satisfied but neither condtion2 nor condtion3 are true  }

This can be further simplified to one condition as:

if(!condition3){

// when  condition1 and condition2 are both satisfied

}

else

// condition3 is met

Now, consider a simple instance dealing with whether to attend school based on certain conditions.

if (temperature< 40)

{

   if (busArrived=="yes")

   {

       if (!sick)

       {

           if (homework=="done")

           {

               printf("Go to school.");

           }

       }                    

   }

}

Here, nested conditionals are evident. This can be restructured into a solitary conditional using the AND logical operator.

if ((temperature <40) && (busArrived=="yes") &&

(!sick) && (homework=="done"))

{    cout<<"Eligible for promotion."; }

The alternate method is utilizing an interface. For example, you can

abstract class Shape{

//declare a method common to all sub classes

  abstract public int area();

// same method that varies by formula of area for different shapes

}

class Triangle extends Shape{

  public int area() {

     // implementation of area code for Triangle

return (width * height / 2);

  }

}

class Rectangle extends Shape{

  public int area() {

     // implementation of area code for Rectangle

    return (width * height)

  }

}

Now, you can readily create Rectangle or Triangle instances and invoke area() for any of those objects, resulting in execution of the appropriate version accordingly.

4 0
2 months ago
Provide an example by creating a short story or explanation of an instance where availability would be broken.
Amiraneli [1052]

Explanation:

Personal Insurance

Understanding workplace confidentiality: Key points

In professions where you advise clients or patients, safeguarding private and sensitive information is essential. But are you knowledgeable about what constitutes a confidentiality breach and how to handle it if it happens?

This passage provides insights into protecting confidential data and identifying breaches in various jobs, emphasizing the significance of confidentiality at work.

What does a breach of confidentiality entail?

Essentially, a breach occurs when information is shared with someone without the explicit consent of its owner. This refers to the failure to respect an individual's privacy or the trust they placed in you while sharing their information.

Why is maintaining confidentiality critical?

Safeguarding confidential information is crucial for those who access or handle such data at work. If confidentiality is compromised, it can jeopardize your professional reputation and relationships with current and future clients, which may lead to termination of contracts or legal consequences.

Therapist/patient confidentiality

Confidentiality for patients is especially vital for therapists and counselors. It plays an essential role in establishing proper boundaries, fostering a trusting therapeutic relationship.

Here are some examples of unintentional breaches of therapist/patient confidentiality:

Disclosing confidential client information to friends or family

Discussing confidential details in public spaces where others can overhear

Leaving computers with confidential information accessible to others

Continuing treatment for a client with known conflicts of interest (e.g., if they are acquainted with family or friends)

When individuals give permission to share information but without clarity, it may lead to misunderstandings and potential breaches (e.g., a patient may consent to share details with a teacher but not with their doctor).

7 0
1 month ago
Other questions:
  • While trying to solve a network issue, a technician made multiple changes to the current router configuration file. The changes
    7·1 answer
  • Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
    12·1 answer
  • . Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    12·1 answer
  • Imagine you were using some of our pixelation tools to create an image and you posted it online for your friends to see - but, a
    11·1 answer
  • 1. Orthographic Drawings are used to express ideas that are more complicated. Explain the purpose of the different views and the
    7·1 answer
  • Factoring of integers. Write a python program that asks the user for an integer and then prints out all its factors. For example
    13·1 answer
  • Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th
    8·1 answer
  • The engineering firm you work for is submitting a proposal to create an amphitheater at a state park. Proposals must be submitte
    15·1 answer
  • Write a class for a Cat that is a subclass of Pet. In addition to a name and owner, a cat will have a breed and will say "meow"
    9·1 answer
  • Given: an int variable k, an int array current Members that has been declared and initialized, an int variable memberID that has
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!