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
Which screen should be open to customize or personalize a desktop background?
stira [4]
Display Properties is the screen that should be open
5 0
3 years ago
Read 2 more answers
How do u know when a website doesnt like u?
stira [4]
Honest answer a website does not have feelings so therefore there is no way to tell if a website likes you or not!! The reason it may not load is because your IT provider or maybe to firewalls that are set up on your modem. Sometimes its not that and you just need to keep you computer up to date that way it can get on the websites! Hope i helped
3 0
4 years ago
This innovator created “honeypots” in which fake accounts are set-up in order to catch cyber criminals.
statuscvo [17]

Answer: A

Explanation:

3 0
4 years ago
Read 2 more answers
Which enables users to try an application before they commit to buying it?
adelina 88 [10]

Answer:

shareware

Explanation:

It is the shareware, which is available for free for a certain period, and after that, the actual fee is charged for continued usage. The public domain is free from copyright, patent or trademark laws, and is the public property. The open-source is the free code of software that is available with code for the whole developer community. And it is shared among all the developers. And the developer can be anybody. The freeware is the software that is provided free of cost by the publisher. And there is no set of rights, licenses or EULA that governs its distribution, and each publisher frames his own set of rules for the usage of the freeware.

8 0
3 years ago
Read 2 more answers
¿Cuál es la diferencia ente un software especializado y uno de uso general? Explica con ejemplos. *
Fofino [41]
I don’t speak spanish :(
7 0
3 years ago
Other questions:
  • The difference between an AutoCorrect entry and a building block is that the building block feature makes corrections automatica
    6·1 answer
  • In which of the following stages of the development process is a team MOST likely to interview a potential user of an app?
    6·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an
    15·1 answer
  • Computer simulations can: A. accurately predict the weather a month in advance.
    11·1 answer
  • Write a repetition statement that outputs the numbers 45 , 51 , . . . , 165 . That is, all of the multiples of 6 in increasing o
    7·1 answer
  • What activities are coordinated by the OS?
    11·1 answer
  • A bicycle sharing company is developing a multi-tier architecture to track the location of its bicycles during peak operating ho
    11·1 answer
  • The use of computer in a modern world is as a result of complexity. true or false
    6·1 answer
  • Does anyone know how to change there Name of the account that shows up? If you do please tell me in a comment and/or Answer.
    6·2 answers
  • Write a python program to print the square of all numbers from 0 to 10.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!