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
Micheal has increased the contrast of the given picture. Which feature or menu option of a word processing program did he use? A
Alex17521 [72]

First of all, Micheal would have inserted an image in the word-processing program. The option to increase or decrease the contrast of an inserted image comes under the format feature.

A. Format

<u>Explanation:</u>

When a user inserts an image, the image is inserted with the same visual setting as it was saved with. The user can increase or decrease the contrast of the image to suit his/her needs.

The format menu provides several other editing options such as altering the brightness, compressing the picture, resizing the picture and even change the inserted picture and many more.

7 0
3 years ago
Mr. Green maintains a spreadsheet containing data on all of his employees, including name, job profile, monthly salary, and home
marta [7]
The answer is C because he'll be able to search up the employees name then it will tell him all the information he needs along with their job profile
6 0
3 years ago
The economic importance of computer viruses​
Lena [83]

Answer:

whats the question?

Explanation:

3 0
2 years ago
Read 2 more answers
9. Name at least two types of hard drives?
JulsSmile [24]
IDE: Integrated drive electronics

Sata:Serial advance technology attachment
5 0
3 years ago
List out the storage measurements units of a computer .<br><br>​
xxTIMURxx [149]

Answer:

Computer storage and memory is often measured in megabytes (MB) and gigabytes (GB). A medium-sized novel contains about 1 MB of information. 1 MB is 1,024 kilobytes, or 1,048,576 (1024x1024) bytes, not one million byte

3 0
3 years ago
Read 2 more answers
Other questions:
  • There are N bulbs numbered from 1 to N, arranged in a row. The first bulb is plugged into the power socket and each successive b
    6·1 answer
  • What is an effective way to display calculations in a Word document
    7·2 answers
  • You can combine the algorithms for converting between infix to postfix and for evaluating postfix to evaluate an infix expressio
    13·1 answer
  • All of the following are strategies to help you prepare for standardized test except <br>​
    5·1 answer
  • Which of the following statements is true? Computer disks are volatile storage devices Volatile storage is lost when a computer
    12·2 answers
  • Which of these programmers creates the core game engine?
    5·2 answers
  • Which 3D game has Bentley the Bear collect gems while avoiding enemy trees, bees, ghosts, skeletons, and Berthilda the witch?
    9·1 answer
  • Stephanie would like to know the average number of regular hours worked by her employees. In cell B11, create a formula using th
    8·1 answer
  • What is the difference between information poor and information rich<br>​
    13·1 answer
  • 30 POINTS FOR THE ANSWER
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!