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
A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that
prisoha [69]

In Python, assume that a file containing a series of integers is named numbers.txt and exist on the computer's disk. Write a program that reads the entire numbers store in the file and calculates their total.

Here is what I have written but it does not run:  

def. main():

   out file=open('numbers.txt','r')

   temp=outfile.readline()

   total=0

   while temp!='':

       t=int(temp)

       total=total+i

       temp=outfile.readline()

       outfile.close()

       print('Total sum is:',total)

main()

Text file is a file named numbers.txt with the numbers 1-50 in it

Learn more:

  • The sum of three consecutive integers is 186. what are the integers

        brainly.com/question/1768254

Keywords: python, integers, computer, numbers, program

6 0
3 years ago
Read 2 more answers
What are the 5 font/typography families
larisa [96]

Answer:

Arial

Helvetica

Verdana

Calibri

Noto

Explanation:

8 0
3 years ago
. What will be the output of the following program?
raketka [301]

Answer:

Similarly x % 100 yields the last two digits. 4.2. Boolean values and expressions¶. The Python type for storing true and false values is called bool

3 0
2 years ago
Select the correct answer.
Ksivusya [100]

I would have to say Effective Communication. Mainly because if everyone you have a team arguing over every option you are not focusing on one thing. This way you can discuss each option and have less of a divide if you all communicate what you feel effectively.

It could also be Leadership because as a leader you can avoid it completely and choose for your team. However based on what they are asking I still believe it would be B.

4 0
3 years ago
Read 2 more answers
Given an array of n distinct integers sorted in ascending order, write a function that returns a Fixed Point in the array, if th
Zinaida [17]

Answer:

The function is as follows:

int returnsFixed(int arr [],int n){

   int retVal = -1;

   for(int i = 0; i<n;i++){

       if(i == arr[i]){

           retVal = i;

           break;

       }

   }

   return retVal;

}

Explanation:

This defines the functionl it receives the array and the length of the array

int returnsFixed(int arr [],int n){

This initializes the return value to -1

   int retVal = -1;

This iterates through the array

   for(int i = 0; i<n;i++){

This checks if i equals arr[i]

       if(i == arr[i]){

If yes, the return value (i.e. the fixed point) is set to i

           retVal = i;

And the code is exited

           break;

       } This ends the if condition

   } This ends the iteration

This returns the calculated fixed point

   return retVal;

}

6 0
3 years ago
Other questions:
  • Where can you find additional commands to include in menu options?
    12·1 answer
  • Someone may choose to own a car instead of leasing because:
    14·2 answers
  • To rotate text in a cell, select the _____ option in the alignment grouping.
    8·1 answer
  • What stage of software development incorporates planning to help make changes in the project plan based of reviews
    12·1 answer
  • is an interviewing method in which a mall interviewer intercepts and directs willing respondents to nearby computers where each
    7·1 answer
  • What command enables you to initialize quotas on a file system?
    9·1 answer
  • The Account class contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and a
    14·1 answer
  • You do not need to remove the lead weights inside tires before recycling them. A) TrueB) False
    15·1 answer
  • To simplify input management, you are asked, neglecting the handling of exceptions, to write a keyboard class so that the input
    11·1 answer
  • A combined counting and logical looping statement may be needed in the following situations: (a). The values stored in a linked
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!