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
How to see if your computer has bluetooth?
RUDIKE [14]
Assuming you're running Windows, click the start button, and then search for "Device Manager" (or open CMD or PowerShell and type devmgmt.msc). Look at the list of devices. If Bluetooth is there, you have it; if it's not there, you don't. 
3 0
2 years ago
What is one way you might code-switch when posting a comment to a class discussion?
irina [24]

Answer:

The term code switching has been expanded and can encapsulate in any situation that speaker find to be switch from vocabulary.

Explanation:

It is a truly remarkable skill when you communicate your emotions, thoughts and opinion to others. It does not mean that we just to communicate our language but our language influence our thought, emotions and language and self identity.

we communicate our culture that is reflected in our language. Our language tells that who we are and from where we comes.

Code switching is related to the speakers alternates use of multiple language. in the one communication.

For example: Grace for beautiful gift ( Esta awesome).

7 0
2 years ago
Create a web page for a fictitious company: Widgets Inc. has hired you to make a mock-up for their new website. They are on a bu
lina2011 [118]

Answer:

.20%

Explanation:

4 0
2 years ago
Anyone willing to help with Excel?!!
anastassius [24]

Hi!

I have a slight understanding of excel, it depends on what you need.

8 0
2 years ago
what will the total power dissipated in the circuit shown in the figure above if M1 has a current reading of 0.04 A.?​
OlgaM077 [116]

Answer:

P=0.24\ W

Explanation:

<u>DC Circuit</u>

The DC circuit shown it the figure has a power source (battery), some resistors, switches and voltage and current meters. The switch S1 is open, so the right branch of the circuit is neglected. Assuming all meters are ideal (no resistive losses), we have a simple series circuit made of resistors R2 and R3.

We are required to compute the total power dissipated in the circuit, which corresponds to the total power delivered by the voltage source.

The power source of V= 6V is delivering a current in the series circuit equal to the current through R1 and R3. That current is the same as that read by M1 known to be I=0.04 A

The power delivered by the source is

P=V.I=6\ V\cdot 0.04\ A

\boxed{P=0.24\ W}

4 0
2 years ago
Other questions:
  • How does Hadoop work? It breaks up Big Data into multiple parts so each part can be processed and analyzed at the same time on o
    5·1 answer
  • 5. Tricks of the language commercials use are called Rhetorical Devices?
    9·1 answer
  • To prepare a data character for transmission, a ____ bit is added to the beginning of the character and informs the receiver tha
    11·1 answer
  • Consider the class ScopeTest defined this way:
    15·1 answer
  • Can someone help me write an algorithm and a flow chart pls for question 3
    7·1 answer
  • To have a reason or purpose to do something
    8·2 answers
  • What are the services offered by web-based email?​
    12·1 answer
  • What is the process of smaw welding​
    11·1 answer
  • Please help me !!
    10·1 answer
  • Which describes the Paradox of Automation?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!