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
olga55 [171]
3 years ago
8

#Write a function called find_median. find_median #should take as input a string representing a filename. #The file correspondin

g to that filename will be a list #of integers, one integer per line. find_median should #return the medi
Computers and Technology
1 answer:
azamat3 years ago
5 0

Answer:

Explanation:

The following is written in Python. It takes in a file, it then reads all of the elements in the file and adds them to a list called myList. Then it sorts the list and uses the elements in that list to calculate the median. Once the median is calculated it returns it to the user. The code has been tested and the output can be seen in the image below.

def find_median(file):

   file = open(file, 'r')

   mylist = []

   for number in file:

       mylist.append(int(number))

   numOfElements = len(mylist)

   mylist.sort()

   print(mylist)

   if numOfElements % 2 == 0:

       m1 = numOfElements / 2

       m2 = (numOfElements / 2) + 1

       m1 = int(m1) - 1

       m2 = int(m2) - 1

       median = (mylist[m1] + mylist[m2]) / 2

   else:

       m = (numOfElements + 1) / 2

       m = int(m) - 1

       median = mylist[m]

   return median

print("Median: " + str(find_median('file1.txt')))

You might be interested in
The _____ establishes that the destination device is present on the network, verifies active service, and informs the destinatio
masya89 [10]

Answer: Three way handshake

Explanation:

The three way handshake is the process in which it established a connection at the destination device in the network. It also verifies the currently active services in the network.

The three way shake process basically uses in the transmission control  protocol(TCP) and it also inform to the destination device about the communication session.

Three way handshake process are properly understand in the TCP segment header by the various values in the two host exchange.

4 0
3 years ago
What is the classification of the Gartner company?
Strike441 [17]

Answer:

It Is Multimedia

Explanation:

Trust Me

3 0
3 years ago
A type of indent where the first line of text starts at the left margin and the second and succeeding lines of text are indented
9966 [12]

Answer: The first line intent

Explanation:

 The first line intent is one of the type of intent and the first line of the text are mainly starts from the left margin. It is one of the most common method to start the line or text with the new paragraph. We use the tab key for creating the first line indent in the word.

In the first line indent the second line are basically known as the succeeding line of the text that contain the various indented bullets.

3 0
4 years ago
Read 2 more answers
Why did the boy run from the pillow...... wrong answers only
Savatey [412]

He thinks there is a demon hiding innit thus, he runs and calls his mom. His mom says "Jimmy there's nothing in that pilow young man!" Jimmy walks back to his room scared if its still there. He hops into bed hoping that he can get a good nights rest. The next day, Jimmy asks if he can go buy another pillow. His mom says "As long as it makes you feel safe then ok." Young Jimmy, jumping in excitement, goes to the checkout zone to buy his new pillow. When they get home, Jimmy and his mom eat dinner and then head for bed. Jimmy hops into bed and knows that everything will be ok. The end.

4 0
3 years ago
What's the inputs and outputs in a kitchen?
SashulF [63]
I really don't know...
6 0
3 years ago
Other questions:
  • A. When executing System.out.println(a1), the toString() method in the Object class is invoked.
    14·1 answer
  • Calculate the total number of bits transferred if 200 pages of ASCII data are sent using asynchronous serial data transfer. Assu
    5·1 answer
  • Jerry is making an address book using a digital database. He has a list of his immediate family and friends but wants to add a f
    9·2 answers
  • My mac book airs touch pad stopped working and i can't click. what do i do?
    5·2 answers
  • Consider relations A and B. Relation A represents the entity on the ""one side"" of a one-to-many relationship; Relation B repre
    11·1 answer
  • Post as a reply your example of "data, which is processed into information" case - examples should not necessarily be related to
    13·1 answer
  • How do you make the "Colorize" feature in GIMP consistent if you cannot connect the different places? Brainliest if you also exp
    12·2 answers
  • What are some things all boomers say.
    12·2 answers
  • If a document is stored on a file server but team members can edit the document​ anonymously, the content on the file server is:
    14·1 answer
  • Explain set associative mapping<br>​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!