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
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "To
weqwewe [10]

Answer:

#include <iostream>

using namespace std;

void PrintPopcornTime(int bagOunces) {

if(bagOunces < 3){

 cout << "Too small";

 cout << endl;

}

else if(bagOunces > 10){

 cout << "Too large";

 cout << endl;

}

else{

 cout << (6 * bagOunces) << " seconds" << endl;

}

}

int main() {

  PrintPopcornTime(7);

  return 0;

}

Explanation:

Using C++ to write the program. In line 1 we define the header "#include <iostream>"  that defines the standard input/output stream objects. In line 2 "using namespace std" gives me the ability to use classes or functions, From lines 5 to 17 we define the function "PrintPopcornTime(), with int parameter bagOunces" Line 19 we can then call the function using 7 as the argument "PrintPopcornTime(7);" to get the expected output.

8 0
3 years ago
Whats the pros about being in the army
Cerrena [4.2K]

Answer:

Benefits that last a lifetime. The Army offers you money for education, comprehensive health care, generous vacation time, family services and support groups, special pay and cash allowances to cover the cost of living.

8 0
4 years ago
NO LINK plsssss just answer
solmaris [256]

Answer:

Explanation:

4 0
2 years ago
A 5-in.-diameter pipe is supported every 9 ft by a small frame consisting of two members asshown. Knowing that the combined weig
jarptica [38.1K]

Answer:

AC: at D , M_max = 12.25 lb-ft

BC: at E , M_max = 8.75 lb-ft

Explanation:

Given:

- The diameter of the pipe d = 5-in

- The pipe is supported every L = 9 ft of pipe in length

- The weight if the pipe + contents W = 10 lb/ft

Find:

determine the magnitude and location of the maximum bending moment in members AC and BC.

Solution:

- The figure (missing) is given in the attachment.

- We will first determine the external forces acting on each member:

             Section: 9-ft section of pipe.

                     Sum of forces perpendicular to member AC = 0

                     F_d - 0.8*W*L = 0

                     F_d = 0.8*10*9 = 72 lb

                     Sum of forces perpendicular to member BC = 0

                     F_e - 0.6*W*L = 0

                     F_e = 0.6*10*9 = 54 lb

              F_d = 72 lb ,  F_e = 54 lb

- Then we will determine the support reactions for each member AC point A and BC point B.

              Section: Entire Frame.

                    Sum of moments about point B = 0

                    -A_y*(18.75/12) + F_d*(d /2*12) + F_e*((11.25-2.5)/12) = 0

                    -A_y*(1.5625) + 15 + 39.375 = 0

                    A_y = 34.8 lb  

                   Sum of forces in vertical direction = 0

                     A_y + B_y - 0.8*F_d - 0.6*F_e = 0

                     B_y = 0.8*(72) + 0.6*(54) - 34.8

                     B_y = 55.2 lb  

                   Sum of forces in horizontal direction = 0

                     A_x + B_x - 0.6*F_d + 0.8*F_e = 0

                     A_x + B_x = 0

               Section: Member AC

                    Sum of moments about point C = 0

                     F_d*(2.5/12) - A_y*(12/12) - A_x*(9/12) = 0

                     72*2.5 - 34.8*12 - 9*A_x = 0

                     A_x = -237.6 / 9 = - 26.4 lb

                     B_x = - A_x = 26.4 lb

                     A_x = -26.4 lb  ,  B_x = 26.4 lb

- Now we will calculate bending moment for each member at different sections.

               Member AC:

                    From point A till just before point D

                     -0.6*A_x*x - A_y*0.8*x + M = 0

                     15.84*x - 27.84*x + M = 0

                      M = 12*x   ..... max value at D, x = 12.25 in

                      M_max = 12*12.25/12 = 12.25 lb-ft

               Member BC:

                    From point B till just before point E

                     -0.8*B_x*x + B_y*0.6*x + M = 0

                     -21.12*x + 33.12*x + M = 0

                      M = -12*x   ..... max value at E, x = 11.25 - 2.5 = 8.75 in

                      M_max = -12*8.75/12 = -8.75 lb-ft

- The maximum bending moments and their locations are:

                      AC: at D , M_max = 12.25 lb-ft

                      BC: at E , M_max = 8.75 lb-ft

5 0
3 years ago
User Location: Inside Viewport Viewport Location: Fresh Viewport in downtown San Fransisco, California Query: [Burger King] Resu
8_murik_8 [283]

Answer:

Steps should you take to rate this result are

  • Check the pin location.
  • Check the official website for the address .
  • Check if there are closer results that we are not returning.
4 0
3 years ago
Other questions:
  • Compute the fundamental natural frequency of the transverse vibration of a uniform beam of rectanqular cross section, with one e
    11·2 answers
  • A steam reformer operating at 650C and 1 atm uses propane as fuel for hydrogen production. At the given operating conditions, th
    12·1 answer
  • A soil has the following Green-Ampt parameters Effective porosity 0.400 Initial volumetric moisture content-15% Hydraulic Conduc
    6·1 answer
  • The air contained in a room loses heat to the surroundings at a rate of 50 kJ/min while work is supplied to the room by computer
    11·2 answers
  • Discuss the chemical and physical properties of crude oil​
    6·1 answer
  • When -iron is subjected to an atmosphere of hydrogen gas, the concentration of hydrogen in the iron, CH (in weight percent), is
    5·1 answer
  • What engine does the mercedes 500e have​
    5·1 answer
  • Identify renewable energy sources you will propose. Explain the key elements to your solution and the basic technical principles
    5·1 answer
  • 3
    6·1 answer
  • Which of the following is most likely to require changes to existing zoning laws?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!