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 large plate is fabricated from a steel alloy that has a plane strain fracture toughness of 78 MPa (70.98 ksi). If the plate is
Reika [66]

Answer:

minimum length of a surface crack is 15.043 mm

Explanation:

given data

strain fracture toughness K = 78 MPa

tensile stress = 345 MPa

Y = 1.04

to find out

minimum length of a surface crack

solution

we find here length of critical interior flaw from formula that is

α  =  \frac{1}{\pi} (\frac{K}{\sigma Y})^2     ....................1

put here value we get

α  =  \frac{1}{\pi} (\frac{78*\sqrt{10^3} }{345*1.04})^2

α  = 15.043 mm

so minimum length of a surface crack is 15.043 mm

7 0
3 years ago
A pressure gage at the inlet to a gas compressor indicates that the gage pressure is 40.0 kPa. Atmospheric pressure is 1.01 bar.
bonufazy [111]

Answer:

Given

inlet Pga =40kpa = 40000pa

Patm=1.01bar = 1.01 x 100000pa =101000pa

exit Pab= 6.5 (inlet Pab)

But generally, Pab = Patm + Pga

1. the absolute pressure of the gas at the inlet, inlet Pab?

inlet Pab = Patm + inlet Pga

            = 101000pa + 40000pa = 141kpa

the absolute pressure of the gas at the inlet, inlet Pab = 141kpa

2. the gage pressure of the gas at the exit? exit Pga?

exit Pab = Patm + exit Pga

exit Pga = exit Pab - Patm

             = (6.5 x 141kpa) - 101kpa

              = 815.5kpa

the gage pressure of the gas at the exit exit Pga=815.5kpa

5 0
3 years ago
When you see a street with white markings only, what kind of street is it?
Georgia [21]

Answer:

it's a one way street

3 0
4 years ago
If superheated water vapor at 30 MPa iscooled at ​constant pressure​, it will eventually become saturated vapor, and with suffic
nirvana33 [79]

Answer:

False.

Explanation:

False. The pressure is above pressure at critical point (22.064 MPa.), the limit where pressure can prevent boiling.

3 0
3 years ago
A flywheel made of Grade 30 cast iron (UTS = 217 MPa, UCS = 763 MPa, E = 100 GPa, density = 7100 Kg/m, Poisson's ratio = 0.26) h
hram777 [196]

Answer:

N = 38546.82 rpm

Explanation:

D_{1} = 150 mm

A_{1}= \frac{\pi }{4}\times 150^{2}

              = 17671.45 mm^{2}

D_{2} = 250 mm

A_{2}= \frac{\pi }{4}\times 250^{2}

              = 49087.78 mm^{2}

The centrifugal force acting on the flywheel is fiven by

F = M ( R_{2} - R_{1} ) x w^{2} ------------(1)

Here F = ( -UTS x A_{1} + UCS x A_{2} )

Since density, \rho = \frac{M}{V}

                        \rho = \frac{M}{A\times t}

                        M = \rho \times A\times tM = 7100 \times \frac{\pi }{4}\left ( D_{2}^{2}-D_{1}^{2} \right )\times t

                        M = 7100 \times \frac{\pi }{4}\left ( 250^{2}-150^{2} \right )\times 37

                        M = 8252963901

∴ R_{2} - R_{1} = 50 mm

∴ F = 763\times \frac{\pi }{4}\times 250^{2}-217\times \frac{\pi }{4}\times 150^{2}

  F = 33618968.38 N --------(2)

Now comparing (1) and (2)

33618968.38 = 8252963901\times 50\times \omega ^{2}

∴ ω = 4036.61

We know

\omega = \frac{2\pi N}{60}

4036.61 = \frac{2\pi N}{60}

∴ N = 38546.82 rpm

7 0
3 years ago
Other questions:
  • A tire-pressure monitoring system warns you with a dashboard alert when one of your car tires is significantly under-inflated.
    6·1 answer
  • 12. The small space above the piston in which fuel is burned is called the
    10·1 answer
  • The fan blades suddenly experience an angular acceleration of 2 rad/s2. If the blades are rotating with an initial angular veloc
    10·1 answer
  • Water drains at a constant rate through a saturated soil column with a diameter of 1.5 feet and a height of 3 feet. The hydrauli
    11·1 answer
  • Which technical planning document defines support tasks?
    7·1 answer
  • A motor cycle is moving up an incline of 1 in 30 at a speed of 80 km/h,and then suddenly the engine shuts down.The tractive resi
    11·1 answer
  • Once you get the answer correct first i will mark you brainliest!!
    15·2 answers
  • The actual tracking weight of a stereo cartridge that is set to track at 3 g on a particular changer can be regarded as a contin
    9·1 answer
  • Is there a project idea, or invention that would be good for<br> my class.
    6·2 answers
  • a low velocity fastening system that is used to drive steel pins or threaded studs into a masonry and steel is a
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!