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
Analyze the following code.
denis-greek [22]

Answer:

C

Explanation:

No explanation, self-explanatory. I used class main instead...

4 0
3 years ago
The safest action to take if someone claiming to be from your banks calls you to ask for account information is to
aalyn [17]
<h2>Answer:</h2>

<u>The correct option is</u><u> (B) hang up and call back using the banks official phone number</u>

<h2>Explanation:</h2>

There are a lot of cases where people pretend to call from the banks where the receivers have the account. The caller tries to take the information from the receiver and pretends to be the bank official. If there is any doubt then the receiver should hang up the call and call back the official number of the bank to confirm that whether somebody has called from the bank to get the information.

8 0
3 years ago
Read 2 more answers
Write two sentences but each one having either computer in it or technology in it. You can use a word more than once in a senten
Ksju [112]

Answer:

Sentences:

1.My computer has a virus

2.Technology may take over the world someday

Explanation:

7 0
2 years ago
Read 2 more answers
Which type of formatting would you apply to spreadsheet data so that each cell is outlined?
rjkz [21]

Answer:

D. Border

Explanation:

Edge 2020

5 0
2 years ago
The measure of error in keyboardist is called?​
Dimas [21]
Jjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
8 0
3 years ago
Other questions:
  • We have to calculate the percentage of marks obtained in three subjects (each out of 100) by student A and in four subjects (eac
    11·1 answer
  • Ill give you brainiest.
    9·1 answer
  • Why is it important to brain storm and develop concepts prior to selecting an idea that you wish to move forward with as a solut
    7·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
  • To give your app users the ability to open your app directly from other apps by clicking a link, you should use:.
    11·1 answer
  • White lines
    7·2 answers
  • Please help me with this
    6·1 answer
  • Rafi is developing an application to send urgent information about global health crises over the Internet to hospitals. He is wo
    6·1 answer
  • An if statement must always begin with the word “if.” True False python
    15·2 answers
  • Computer works on the basis of?​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!