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
dmitriy555 [2]
3 years ago
15

Define a function max_n(arr, n) that takes in an array and an integer as arguments. Your function will then return the n largest

values from that array as an array containing n elements. It is safe to assume that arr will have at least n elements. The resulting array should have the largest number on the end and the smallest number at the beginning.
Computers and Technology
1 answer:
NikAS [45]3 years ago
4 0

Answer:

def max_n(arr, n):

   arr.sort()

   i = len(arr)-n

   return arr[i:]

Explanation:

Define a function called max_n that takes two parameters, an array and an integer

Sort the array

In order to get the last n largest values, we need to slice the array. To do that we need a starting point. Our starting point of slicing will be the "lentgh of the array - n". That means, if we start slicing from that index to the last in the sorted array, we will get the last n largest values.

Assume array is 10, 2, 444, 91 initially.

When we sort it, it becomes 2, 10, 91, 444

Now let's say we want last 2 largest values, our sliced array index should start from 2 and go until the end

i = 4 - 2 = 2 → arr[2:]  will return us 91 and 444

You might be interested in
Please helpppppppppppppp
viktelen [127]

Answer:

its D

Explanation:

The social worker likes to work with other people, so he/she might not like working alone.

6 0
2 years ago
What is the computer that is connected to a<br> server
sergiy2304 [10]

Answer:

peripheral device network connection

5 0
2 years ago
Read 2 more answers
HELP GENIUS Rank :))) DoNT answer If you don't know
RideAnS [48]

An instance in my life where I rendered services was when I worked in a grocery store.

The roles of entrepreneur include:

  • Allocating employees duties.
  • Improving standard of living.
  • Taking risks.

The three challenges that a young entrepreneur faces today include:

  • Financial instability.
  • Conflicts with education.
  • Lack of business skills.

The top three characteristics of an entrepreneur include:

  • Innovation.
  • Confidence
  • Risk taking

<h3>Who's an entrepreneur?</h3>

It should be noted that a entrepreneur is an individual who owns business and take risks.

The roles of entrepreneur include allocating employees duties, improving standard of living, and taking risks

Learn more about entrepreneur on:

brainly.com/question/353543

#SPJ1

3 0
1 year ago
Advantages of a computer​
Bess [88]

Answer:

It eases work.

It is deligent.

It is versatile.

8 0
3 years ago
Write a program that asks the user for the number of males and the number of females registered in a class. The program should d
Bond [772]

Answer:

import java.util.Scanner;

public class PercentagePopulation {

public static void main(String[] args) {

 // 1. Create an object of the Scanner class

 // This will allow for user's inputs

 Scanner input = new Scanner(System.in);

 // 2. Create a prompt asking the user to enter the number of males

 System.out.println("Please enter the number of males");

 // 3. Receive the number entered by the user and store in an int

 // variable called  number_of_males.

 int number_of_males = input.nextInt();

 // 4. Create a prompt asking the user to enter the number of

               // females

 System.out.println("Please enter the number of females");

 // 5. Receive the number entered by the user and store in an int

 // variable  called, number_of_females

 int number_of_females = input.nextInt();

 // 6. Find the sum of the number of males and females

 // Store the result in an int variable called total.

 int total = number_of_males + number_of_females;

 // 7. Find the percentage of males by using the appropriate

 // formula.  Do a type-casting to allow for division in floating point

               // representation by prepending the number_of_males by (double)

 double percentagemales = (double) number_of_males / total * 100.0;

 // 8. Find the percentage of females by using the appropriate

 // formula.  Do a type casting to allow for division in floating point

               // representation by prepending the number_of_males by (double)

 double percentagefemales = (double) number_of_females / total * 100.0;

 // 9. Print out the results

 System.out.println("Percentage males : " + percentagemales + "%");

 System.out.println("Percentage females : " + percentagefemales + "%");

}

}

Explanation:

Please go through the comments in the code to give an explanation of the program. The source code file has also been added to this response. Please download it and go through it.

Download java
4 0
3 years ago
Other questions:
  • Plugging in a cable is a good troubleshooting technique. <br> True or false
    5·1 answer
  • 1. The future of 2D animation does not include hand-drawing. (1 point)
    13·1 answer
  • Which of the following is most likely to be a result of hacking? Group of answer choices slowing of network speed certain Web si
    13·1 answer
  • The two principal catalysts for the Information Age have been:________.
    15·1 answer
  • As the network engineer, you are asked to design an IP subnet plan that calls for three subnets. The largest subnet needs a mini
    14·1 answer
  • (5 points) Create a user-defined data structure (i.e., struct) called Point that represents a two-dimensional Cartesian coordina
    5·1 answer
  • Can someone explain what Bytes are? I would really like to know.
    5·2 answers
  • What keyword is used in Java to create a parent/child relationship between two classes?
    14·1 answer
  • Which of the following online creation tools will be used if a person wants to create a video presentation?
    8·1 answer
  • Write a program that generates 100 random numbers and keeps a count of how many of those random numbers are even and how many of
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!