answer.
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]
2 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]2 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 steam power plant operates on an ideal reheat- regenerative Rankine cycle and has a net power output of 80 MW. Steam enters th
trasher [3.6K]

Answer:

flow(m) = 54.45 kg/s

thermal efficiency u = 44.48%

Explanation:

Given:

- P_1 = P_8 = 10 KPa

- P_2 = P_3 = P_6 = P_7 = 800 KPa

- P_4 = P_5 = 10,000 KPa

- T_5 = 550 C

- T_7 = 500 C

- Power Output P = 80 MW

Find:

-  The mass flow rate of steam through the boiler

-  The thermal efficiency of the cycle.

Solution:

State 1:

P_1 = 10 KPa , saturated liquid

h_1 = 192 KJ/kg

v_1 = 0.00101 m^3 / kg

State 2:

P_2 = 800 KPa , constant volume process work done:

h_2 = h_1 + v_1 * ( P_2 - P_1)

h_2 = 192 + 0.00101*(790) = 192.80 KJ/kg

State 3:

P_3 = 800 KPa , saturated liquid

h_3 = 721 KJ/kg

v_3 = 0.00111 m^3 / kg

State 4:

P_4 = 10,000 KPa , constant volume process work done:

h_4 = h_3 + v_3 * ( P_4 - P_3)

h_4 = 721 + 0.00111*(9200) = 731.21 KJ/kg

State 5:

P_5 = 10,000 KPa , T_5 = 550 C

h_5 = 3500 KJ/kg

s_5 = 6.760 KJ/kgK

State 6:

P_6 = 800 KPa , s_5 = s_6 = 6.760 KJ/kgK

h_6 = 2810 KJ/kg

State 7:

P_7 = 800 KPa , T_7 = 500 C

h_7 = 3480 KJ/kg

s_7 = 7.870 KJ/kgK

State 8:

P_8 = 10 KPa , s_8 = s_7 = 7.870 KJ/kgK

h_8 = 2490 KJ/kg

- Fraction of steam y = flow(m_6 / m_3).

- Use energy balance of steam bleed and cold feed-water:

                                        E_6 + E_2 = E_3

               flow(m_6)*h_6 + flow(m_2)*h_3 = flow(m_3)*h_3

                                    y*h_6 + (1-y)*h_3 = h_3

                                  y*2810 + (1-y)*192.8 = 721

Compute y:                          y = 0.2018

- Heat produced by the boiler q_b:

                             q_b = h_5 - h_4 +(1-y)*(h_7 - h_8)

                    q_b = 3500 -731.21 + ( 1 - 0.2018)*(3480 - 2810)

Compute q_b:               q_b = 3303.58 KJ/ kg

-Heat dissipated by the condenser q_c:

                                       q_c = (1-y)*(h_8 - h_1)

                                 q_c= ( 1 + 0.2018)*(2810 - 192)

Compute q_c:               q_c = 1834.26 KJ/ kg

- Net power output w_net:

                                     w_net = q_b - q_c

                                w_net = 3303.58 - 1834.26

                                    w_net = 1469.32 KJ/kg

- Given out put P = 80,000 KW

                                     flow(m) = P / w_net

compute flow(m)          flow(m) = 80,000 /1469.32 = 54.45 kg/s

- Thermal efficiency u:

                                     u = 1 - (q_c / q_b)

                                     u = 1 - (1834.26/3303.58)

                                     u = 44.48 %

5 0
2 years ago
An electrical utility delivers 6.25E10 kWh of power to its customers in a year. What is the average power required during the ye
Sindrei [870]

Answer:

The overall Utility delivered to customers in a year 'U' = 6.25 X 10¹⁰Kwh

However, the average power P, required for a year, t  = ? Kw

Expressing their relationship, we will have

             U = P x t

Given t = 1 year = 24 x 365 hours (assume a year operation is 365 days)

          t = 8760 hours

P = \frac{62500000000}{8760}

P = 7134.7Kw

Hence, the average power required during the year is 7,135Kw

Now to calculate the energy used by the power plant in a year (in quads)?

Recall, Efficiency, η = Power Output/Power Input (100)

so, we have

η = P₀/P₁, given

0.45 = \frac{7134.7Kw}{P₁}

P₁ = 15,855Kw

the total energy E₁ used in a year = 15,855x24x365 = 138.89MJoules

So to convert this to quads, Note;

1 quads of energy = 10¹⁵ Joules

The total energy used is 0.000000139 quads

Now to find the cubic feet of natural gas required to generate this power?

Note: 0.29Kwh of Power generated  = 1 cubic feet of natural gas used

Since, the power plant generated = 62500000000Kwh

The cubic feet of natural gas used = \frac{62500000000}{0.29}

Hence, 2.155x10²⁰cubic feet of N.gas was used to generate this much power.

8 0
2 years ago
Water is flowing in a metal pipe. The pipe OD (outside diameter) is 61 cm. The pipe length is 120 m. The pipe wall thickness is
Yuki888 [10]

Answer:

1113kN

Explanation:

The ouside diameter OD of the pipe is 61cm and the thickness T is 0.9cm, so the inside diameter ID will be:

Inside Diameter = Outside Diameter - Thickness

Inside Diameter = 61cm - 0.9cm = 60.1cm

Converting this diameter to meters, we have:

60.1cm*\frac{1m}{100cm}=0.601m

This inside diameter is useful to calculate the volume V of water inside the pipe, that is the volume of a cylinder:

V_{water}=\pi  r^{2}h

V_{water}=\pi (\frac{0.601m}{2})^{2}*120m

V_{water}=113.28m^{3}

The problem gives you the water density d as 1.0kg/L, but we need to convert it to proper units, so:

d_{water}=1.0\frac{Kg}{L}*\frac{1L}{1000cm^{3}}*(\frac{100cm}{1m})^{3}

d_{water}=1000\frac{Kg}{m^{3}}

Now, water density is given by the equation d=\frac{m}{V}, where m is the water mass and V is the water volume. Solving the equation for water mass and replacing the values we have:

m_{water}=d_{water}.V_{water}

m_{water}=1000\frac{Kg}{mx^{3}}*113.28m^{3}

m_{water}=113280Kg

With the water mass we can find the weight of water:

w_{water}=m_{water} *g

w_{water}=113280kg*9.8\frac{m}{s^{2}}

w_{water}=1110144N

Finally we find the total weight add up the weight of the water and the weight of the pipe,so:

w_{total}=w_{water}+w_{pipe}

w_{total}=1110144N+2500N

w_{total}=1112644N

Converting this total weight to kN, we have:

1112644N*\frac{0.001kN}{1N}=1113kN

7 0
2 years ago
Michelle is the general manager of a power plant. This morning, she will meet with city officials to discuss environmental issue
Irina-Kira [14]

Answer:

interpersonal.

Explanation:

Out of all the activities performed by Michelle, three activities involves the interpersonal skills.

1. Meeting with city officials

2. Meeting with section managers

3. Handling the complaint filed by an employee

All these activities involves interpersonal skills. Hence, we can say that she had spent her most of the day by using the interpersonal skills.

6 0
2 years ago
Oliver is designing a new children’s slide to increase the speed at which a child can descend. His first design involved steel b
AVprozaik [17]

Answer:

The correct option is;

A) Steel becomes too hot in the Sun and can burn the children

Explanation:

The properties of steel includes;

Low specific heat capacity, high thermal and electrical toughness, high hardness, high tensile strength, high yield strength, appreciable elongation, high fatigue strength, can easily corrode, high malleability and ability to creep

Therefore, due to the low specific heat capacity, which is 0.511 J/(g·°C) and high conductivity of steel which is about 32 W/(m·k), the temperature of the steel can rapidly rise and the hot steel surface can readily conduct the heat, (due to the temperature difference) to other bodies that come in contact

8 0
2 years ago
Other questions:
  • generally compound curves are not filtered recommended for A. Road B. water way C. underground road D. rail way​
    12·1 answer
  • Which of the two materials (brittle vs. ductile) usually obtains the highest ultimate strength and why?
    5·1 answer
  • Determine the amount of gamma and alpha phases in a 10-kg, 1060 steel casting as it is being cooled to the following temperature
    6·1 answer
  • An excavation is at risk for cave-in and water accumulation because of the excess soil that has accumulated. What type of excava
    12·1 answer
  • Water flows downward through a vertical 10-mm-diameter galvanized iron pipe with an average velocity for 5.0 m/s and exits as a
    5·1 answer
  • tech A says that a Hall-effect sensor can be used in an electronic ignition system. Tech B says that an optical-type sensor can
    6·1 answer
  • The small 5-oz slider A moves without appreciable friction in the hollow tube, which rotates in a horizontal plane with a consta
    7·1 answer
  • A piece of corroded metal alloy plate was found in a submerged ocean vessel. It was estimated that the original area of the plat
    6·1 answer
  • A thin-walled tube with a diameter of 6 mm and length of 20 m is used to carry exhaust gas from a smoke stack to the laboratory
    7·1 answer
  • What ratio between differential gain and common-mode gain is called​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!