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
lisov135 [29]
3 years ago
9

PythonA group of statisticians at a local college has asked you to create a set of functionsthat compute the median and mode of

a set of numbers, as defined in Section5.4. Define these functions in a module named stats.py. Also include a functionnamed mean, which computes the average of a set of numbers. Each functionshould expect a list of numbers as an argument and return a single number. Eachfunction should return 0 if the list is empty. Include a main function that tests thethree statistical functions with a given list
Engineering
1 answer:
skelet666 [1.2K]3 years ago
3 0

Answer:

  1. def median(l):
  2.    if(len(l) == 0):
  3.       return 0
  4.    else:
  5.        l.sort()
  6.        if(len(l)%2 == 0):
  7.            index = int(len(l)/2)
  8.            mid = (l[index-1] + l[index]) / 2
  9.        else:
  10.            mid = l[len(l)//2]  
  11.        return mid  
  12. def mode(l):
  13.    if(len(l)==0):
  14.        return 0
  15.    mode = max(set(l), key=l.count)
  16.    return mode  
  17. def mean(l):
  18.    if(len(l)==0):
  19.        return 0
  20.    sum = 0
  21.    for x in l:
  22.        sum += x
  23.    mean = sum / len(l)
  24.    return mean
  25. lst = [5, 7, 10, 11, 12, 12, 13, 15, 25, 30, 45, 61]
  26. print(mean(lst))
  27. print(median(lst))
  28. print(mode(lst))

Explanation:

Firstly, we create a median function (Line 1). This function will check if the the length of list is zero and also if it is an even number. If the length is zero (empty list), it return zero (Line 2-3). If it is an even number, it will calculate the median by summing up two middle index values and divide them by two (Line 6-8). Or if the length is an odd, it will simply take the middle index value and return it as output (Line 9-10).

In mode function, after checking the length of list, we use the max function to estimate the maximum count of the item in list (Line 17) and use it as mode.

In mean function,  after checking the length of list,  we create a sum variable and then use a loop to add the item of list to sum (Line 23-25). After the loop, divide sum by the length of list to get the mean (Line 26).

In the main program, we test the three functions using a sample list and we shall get

20.5

12.5

12

You might be interested in
A ________ can be installed in a cast-iron block to repair a worn or cracked cylinder. Question 24 options:
VLD [36.1K]

Answer:

Cylinder sleeve

Explanation:

7 0
2 years ago
Which metal is used in planes.
wel

Answer:

<h2>Steel</h2>

Explanation:

Steel is the metal that using in planes.

Aluminum and titanium also used in this aircraft industry.

Aluminum is ideal for aircraft manufacture because it's lightweight and strong.

<em>hope</em><em> </em><em>this</em><em> </em><em>helps</em><em>!</em><em>!</em>

<em>have</em><em> </em><em>a</em><em> </em><em>nice</em><em> </em><em>day</em><em>!</em>

<em>follow</em><em> </em><em>me</em><em> </em><em>=</em><em>=</em><em>></em><em> </em><em>Hi1315</em>

5 0
3 years ago
Read 2 more answers
A thick oak wall initially at 25°C is suddenly exposed to gases for which T =800°C and h =20 W/m2.K. Answer the following questi
Schach [20]

Answer:

a) What is the surface temperature, in °C, after 400 s?

   T (0,400 sec) = 800°C

b) Yes, the surface temperature is greater than the ignition temperature of oak (400°C) after 400 s

c) What is the temperature, in °C, 1 mm from the surface after 400 s?

   T (1 mm, 400 sec) = 798.35°C

Explanation:

oak initial Temperature = 25°C = 298 K

oak exposed to gas of temp = 800°C = 1073 K

h = 20 W/m².K

From the book, Oak properties are e=545kg/m³   k=0.19w/m.k   Cp=2385J/kg.k

Assume: Volume = 1 m³, and from energy balance the heat transfer is an unsteady state.

From energy balance: \frac{T - T_{\infty}}{T_i - T_{\infty}} = Exp (\frac{-hA}{evCp})t

Initial temperature wall = T_i

Surface temperature = T

Gas exposed temperature = T_{\infty}

6 0
3 years ago
A 0.25in diameter steel rod BC is securely attached between two identical 1in diameter copper rods (AB and CD). Find the torque
Helen [10]

Answer:

Tmax= 46.0 lb-in

Explanation:

Given:

- The diameter of the steel rod BC d1 = 0.25 in

- The diameter of the copper rod AB and CD d2 = 1 in

- Allowable shear stress of steel τ_s = 15ksi

- Allowable shear stress of copper τ_c = 12ksi

Find:

Find the torque T_max

Solution:

- The relation of allowable shear stress is given by:

                             τ = 16*T / pi*d^3

                             T = τ*pi*d^3 / 16

- Design Torque T for Copper rod:

                             T_c = τ_c*pi*d_c^3 / 16

                             T_c = 12*1000*pi*1^3 / 16

                             T_c = 2356.2 lb.in

- Design Torque T for Steel rod:

                             T_s = τ_s*pi*d_s^3 / 16

                             T_s = 15*1000*pi*0.25^3 / 16

                             T_s = 46.02 lb.in

- The design torque must conform to the allowable shear stress for both copper and steel. The maximum allowable would be:

                             T = min ( 2356.2 , 46.02 )

                             T = 46.02 lb-in

6 0
3 years ago
A fixed mass of saturated water vapor at 400 kpa is isothermally cooled until it is a saturated liquid. Calculate the amount of
Kazeer [188]
This is the explanation

6 0
3 years ago
Other questions:
  • The uniform dresser has a weight of 90 lb and rests on a tile floor for which the coefficient of static friction is 0.25. If the
    6·1 answer
  • A Michelson interferometer operating at a 500 nm wavelength has a 3.73-cm-long glass cell in one arm. To begin, the air is pumpe
    9·1 answer
  • A fluid flows steadily through a pipe with a uniform cross sectional area. The density of the fluid decreases to half its initia
    6·1 answer
  • You are an engineer at company XYZ, and you are dealing with the need to determine the maximum load you can apply to a set of bo
    13·1 answer
  • 3. When performing overhead work on scaffolding, what protective measures must be taken to prevent objects
    9·1 answer
  • List five things the welding symbol will tell the welder about the weld that is to be made.​
    13·1 answer
  • Determine the average power, complex power and power factor (including whether it is leading or lagging) for a load circuit whos
    9·2 answers
  • Name the four ways in which heat is transferred from a diesel engine
    7·1 answer
  • Select the correct answer.
    8·1 answer
  • A cross beam in a highway bridge experiences a stress of 14 ksi due to the dead weight of the bridge structure. When a fully loa
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!