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
What two items must be passed in a tuple to the socket module's connect method in order to connect a socket? (choose two.)
Gekata [30.6K]

The amount of data that can be read from the socket in bytes at most.

<h3>What is socket?</h3>
  • Using socket endpoints on top of the operating system, the "socket" module specifies how server and client machines can communicate at the hardware level.
  • Both connection-oriented and connectionless network protocols are supported by the "socket" API.
  • Using socket endpoints on top of the operating system, the "socket" module specifies how server and client machines can communicate at the hardware level.
  • Both connection-oriented and connectionless network protocols are supported by the "socket" API.
  • An implementation of sockets in a library allows you to use them in your software for Internet communication.

To learn more about socket, refer to:

brainly.com/question/27814017

#SPJ4

6 0
1 year ago
There exists a data type Date with member function Increment that increments the current Date object by one. The ++ operator is
nalin [4]

Answer:

Date Date::operator++( int )

{

Date temp = *this;

Increment();

return temp;

}

Explanation:

Of options 1 through 4, only option 4 correctly implement the post increment of the ++ operator.

Interpreting each line of option for and comparing it to other options

Line 1: Date Date::operator++( int )

This declares the data type and its ++ operator

This is same for all options

Line 2: The Date type needs to be declared

In option 4, it was declared correctly as Date temp = *this;  using a pointer variable *this.

Here, option 2 is removed from the list of possible options.

Comparing other options

Line 3: The member increment option needs to be declared after the declaration of the date type variable.

This is correctly declared as Increment();  in option 4

Here, option 3 is removed from the list of possible options.

Comparing other options

Line 4: The value declared variable temp needs to be returned the way it was declared (without pointer indicator)

Hence, option 4 is best appropriate

3 0
3 years ago
Universal Containers wants to use a sandbox with real data in it. Which Sandboxes three would you recommend?
laila [671]

Answer:

c. Full Sandbox

d. Partial Sandbox

e. Developer Pro

Explanation:

Universal Containers wants to use a sandbox with real data in it. Which Sandboxes three would you recommend?

a. Test Sandbox

c. Test Sandbox

c. Full Sandbox

d. Partial Sandbox

e. Developer Pro

From the question, we are informed that Universal Containers wants to use a sandbox with real data in it. In this case I will recommend Full Sandbox, Partial Sandbox and Developer Pro.

Sandboxes. In cybersecurity sandbox can be explained as security mechanism that is utilized to separate running programs, and this is an effort utilized to curb system failure as well as software vulnerabilities to disperse.

Sandboxes are crucial when executing suspicious code, it helps to do this so that the host device is is not put to risk of harm. Since, Containers wants to use a sandbox with real data in it then the three types of sandboxes can be use.

✓Full sandboxes allows performance testing as well as staging it can be regarded as copy of production org, and these can be objects attachment and others

✓Partial Copy Sandbox can be allows copying of configuration and part of one's data, in order to allow new configuration testing with one's real data.

5 0
2 years ago
1 #include 2 3 int max2(int x, int y) { 4 int result = y; 5 if (x &gt; y) { 6 result = x; 7 } 8 return result; 9 } 10 11 int max
Serhud [2]

Answer:

7

Explanation:

#include <stdio.h>

int max2(int x, int y) {

   int result = y;

   if (x > y) {

       result = x;

   }

   return result;

}

int max3(int x, int y, int z) {

   return max2(max2(x,y),z);

}

int main() {

   int a = 5, b = 7, c = 3;

   printf("%d",max3(a, b, c));

   printf("");

   return 0;

}

Hi, first of all, next time you post the question, it would be nice to copy and paste like above. This will help us to read the code easily. Thanks for your cooperation.

We start from the main function:

The variables are initialized → a = 5, b = 7, c = 3

max3 function is called with previous variables and the result is printed → printf("%d",max3(a, b, c));

We go to the max3 function:

It takes 3 integers as parameters and returns the result of → max2(max2(x,y),z)

Note that max2 function is called two times here (One call is in another call actually. That is why we need to first evaluate the inner one and use the result of that as first parameter for the outer call)

We go to the max2 function:

It takes 2 integers as parameters. If the first one is greater than the second one, it returns first one. Otherwise, it returns the second one.

First we deal with the inner call. max2(x,y) is max2(5,7) and the it returns 7.

Now, we need to take care the outer call max2(7, z) is max2(7, 3) and it returns 7 again.

Thus, the program prints 7.

6 0
2 years ago
Switched backbone networks:_____.a. always use a ring topology.b. require much more management that do routed backbone networks.
Gre4nikov [31]

Answer:

c

Explanation:

spongo  

7 0
3 years ago
Other questions:
  • The item in this illustration that is highlighted is the _____. quick access tool bar view buttons status bar zoom control
    10·2 answers
  • . Alex discovered a bunch of SATA drives in a box at the office and needs to check the contents. What can he do so that Windows
    13·1 answer
  • What is the next series of dragon ball super
    6·2 answers
  • Cloud kicks recently completed the implementation of sales cloud. Cloud kicks has trained the users to use the mobile app to acc
    12·1 answer
  • Which is a basic job requirement for a career in corrections services?
    13·1 answer
  • How has technology impacted our lives and the world we live in? In your own words.
    9·1 answer
  • Heyyyyyy who likes anime​
    12·2 answers
  • Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither.
    6·2 answers
  • nts/viewer/classes/289ef1a5d7c341c284010 Select the compound inequality shown on the graph. 5 4 3 2 1 0 1 2 를 4​
    6·1 answer
  • What is 11x12x12x14x15x16
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!