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
vaieri [72.5K]
3 years ago
14

Modify the list according to the following: append the smallest value at the end of the list when all numbers in the list are ne

gative, append the largest value at the end of the list when all numbers are greater than or equal t。О. Leave the list untouched otherwise. Sample Inputs/Outputs: Example Call: list_min_max_same ([-1, -99,-81) Expected Result: -1,-99, -8,-99] Example input: list_min_max_same ([1,99,8]) Expected Result: [1,99,8,99 Example input: list_min_max_same ([-1,99,-81)
Computers and Technology
1 answer:
ddd [48]3 years ago
3 0

Answer:

The solution code is written in Python 3:

  1. def modifyList(listNumber):
  2.    posCount = 0
  3.    negCount = 0
  4.    for x in listNumber:
  5.        if x > 0:
  6.            posCount += 1
  7.        else:
  8.            negCount += 1
  9.    
  10.    if(posCount == len(listNumber)):
  11.        listNumber.append(max(listNumber))
  12.    
  13.    if(negCount == len(listNumber)):
  14.        listNumber.append(min(listNumber))
  15.    
  16.    print(listNumber)
  17. modifyList([-1,-99,-81])
  18. modifyList([1,99,8])
  19. modifyList([-1,99,-81])

Explanation:

The key step to solve this problem is to define two variables, posCount and negCount, to track the number of positive value and negative value from the input list (Line 2 - 3).

To track the posCount and negCount, we can traverse through the for-loop and create if else statement to check if the current number x is bigger than 0 then increment posCount by 1 otherwise increment negCount (Line 5- 9).

If all number in the list are positive, the posCount should be equal to the length of the input list and the same rule is applied to negCount. If one of them happens, the listNumber will append either the maximum number (Line 11 -12) or append the minimum number (Line 14-15).

If both posCount and negCount are not equal to the list length, the block of code Line 11 -15 will be skipped.

At last we can print the listNumber (Line 17).

If we test our function using the three sets of input list, we shall get the following results:

[-1, -99, -81, -99]

[1, 99, 8, 99]

[-1, 99, -81]

You might be interested in
Explain briefly how learning how to follow can make a person a good leader
Masja [62]

By  learning how to follow, one can  be a good leader because: Looking up to a leader and following them help to:

  • Keep one's ego in check and one can be able to be a good ego manager.
  • They create strong credibility.
  • They help use to focus our efforts for maximum impact.

<h3>How does being a good follower make you a good leader?</h3>

As a good follower, a person can be able to have the boldness and confidence to be able to respectfully talk about a lot of things with their leader if you see that you're not going in the right way.

Note that  one can trust your leader and this will boast up the spirit of your input and engagement in all.

Hence, By  learning how to follow, one can  be a good leader because: Looking up to a leader and following them help to:

  • Keep one's ego in check and one can be able to be a good ego manager.
  • They create strong credibility.
  • They help use to focus our efforts for maximum impact.

Learn more about good leader from

brainly.com/question/12522775

#SPJ1

3 0
1 year ago
Explain how loops can be utilized in list processing. Please provide Python examples in your response.
Dominik [7]

Answer:

data = [0,1,2,3,4]

for i in range(4):

   print(data[i])

   i+=1

Explanation:

Loops can be utilized in a listing process by looping back to a list with a variable while the loop increases that variable to give a different response from the list.

8 0
2 years ago
A DFA is equivalent in power to an NFA. True False
sattari [20]

Answer: True

Explanation:

  Yes, the given statement is true that a DFA is equivalent to NFA in terms of power. For any type of NFA we can easily build an equal DFA so, the NFA are not much powerful as compared to DFA. Both NFA and DFA are characterized by a similar type of class.

DFA is a special case of NFA and They both defined in the same class of language. Each condition in the DFA get summarized by all the condition that the NFA has itself.

4 0
2 years ago
Email Communication has it own set of etiquette guidelines for users to follow if they want to be effective communicators. Which
Olin [163]
You answer is most likely D.
5 0
2 years ago
In the Dognition_aggregated_by_DogID data set, what is consistent about the relationship between breeding group and number of te
snow_tiger [21]

Answer:

Toy dogs

Explanation:

Tableau is an application used for statistically analyzing and visualizing data. It is very popular for its ecstatic data visualization figures and works with all dataset types to create a tableau data format.

The Dognition_aggregated_by_DogID dataset holds data for the different dog types, breeding, and tests done on them. The consistent relation between the breeding group column and tests completed is the toy dogs.

3 0
3 years ago
Other questions:
  • Most of the pollution in the ocean comes from:
    11·1 answer
  • Please Help!
    14·2 answers
  • :If a process terminates, will its threads also terminate or will they continue to run? Explain your answer.
    14·1 answer
  • What is the base for a hexadecimal number system?
    11·1 answer
  • Match each term in the second column with its correct definition in the first column. Write the letter of the term on the blank
    12·1 answer
  • Because all the IEEE WLAN features are isolated in the PHY and ____________ layers, practically any LAN application will run on
    11·1 answer
  • What will the computer do in response to a line of code reading # name = input("What is your name?")
    7·1 answer
  • Discuss the term internal control​
    12·1 answer
  • Hola, alguien aquí me podría ayudar dándome ideas a cerca de office (Word, PowerPoint o Excel) estoy desesperada no puedo pensar
    11·1 answer
  • What does PR stand for ?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!