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
How do you change between worksheets inside an excel workbook?
pochemuha
The correct answer is A
8 0
3 years ago
Read 2 more answers
(a) Explain the difference between a web browser and a search engine.​
mamaluj [8]

Answer: a browser is your access to the internet, and a search engine allows you to search the internet once you have access.

Explanation:

3 0
3 years ago
Assume that sentence is a variable of type String that has been assigned a value. Assume furthermore that this value is a String
disa [49]

Answer:

//get the sentence from the user

          Console.WriteLine("Enter your sentence");

           //read the user information

           string ans = Console.ReadLine();

           //check if sentence ends with period

          if(!ans.EndsWith("."))

           {

               Console.WriteLine("Sentence should end with period");

               Environment.Exit(0);

           }

           //declear empty string firstword

           string firstWord = "";

           //split the requested sentence using single space character

          string[] splitans =  ans.Split(' ');

           //assign firstword

           firstWord = splitans[0];

           //print out firstword

          Console.WriteLine(firstWord);

Explanation:

The program uses c#.

5 0
3 years ago
In c++ 11, the ________ tells the compiler to determine the variable's data type from the initialization value.
sergiy2304 [10]
<span>In describing an Initialization is when a value is assigned to a variable as part of the variable's definition or the assinged values to variables are defined whenever. 

The best answer would be is that they present the keyword,  when they tell the compiler.</span>
3 0
3 years ago
Hi who plays among us
Ray Of Light [21]

Answer:

Me

Explanation:

Lol

8 0
3 years ago
Other questions:
  • If I make a Zoom Meeting, would you join it?
    7·2 answers
  • What is the meaning of Android
    12·2 answers
  • DJ Davon is making a playlist for an internet radio show; he is trying to decide what 1212 songs to play and in what order they
    12·1 answer
  • To apply the StartSafe philosophy to preventing workplace violence, what are the three steps to follow? A. Plan for your job req
    12·2 answers
  • Which of the following is NOT a goal of a Material Requirements Plans (MRP)?
    12·1 answer
  • The amount of pressure a power source creates to move electrons. *
    9·1 answer
  • Clasifica los documentos comerciales en activo, pasivo o patrimonial para cada operacion:
    14·1 answer
  • Google Slides is most similar to which of the following programs?
    10·2 answers
  • List how much hard disk capacity you recommend, and write a sentence explaining why.
    8·1 answer
  • Who was the first person to develop http the language in which servers and browsers communicate
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!