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
Fuel filters are being replaced on a HPCR diesel
saw5 [17]

Answer:) The correct answer is B. at the end of the fuel rail.

2) The one who is correct is the Technician A.

Explanation:

7 0
3 years ago
QUESTION:
pentagon [3]
74 cycles it’s what u need
7 0
3 years ago
The 150-lb man sits in the center of the boat, which has a uniform width and a weight per linear foot of 3 lb>ft. Determine t
irina1246 [14]

Answer:

M = 281.25 lb*ft

Explanation:

Given

W<em>man</em> = 150 lb

Weight per linear foot of the boat: q = 3 lb/ft

L = 15.00 m

M<em>max</em> = ?

Initially, we have to calculate the Buoyant Force per linear foot (due to the water exerts a uniform distributed load upward on the bottom of the boat):

∑ Fy = 0  (+↑)     ⇒    q'*L - W - q*L = 0

⇒       q' = (W + q*L) / L

⇒       q' = (150 lb + 3 lb/ft*15 ft) / 15 ft

⇒       q' = 13 lb/ft   (+↑)

The free body diagram of the boat is shown in the pic.

Then, we apply the following equation

q(x) = (13 - 3) = 10   (+↑)

V(x) = ∫q(x) dx = ∫10 dx = 10x   (0 ≤ x ≤ 7.5)

M(x) = ∫10x dx = 5x²  (0 ≤ x ≤ 7.5)

The maximum internal bending moment occurs when x = 7.5 ft

then

M(7.5) = 5(7.5)² = 281.25 lb*ft

8 0
3 years ago
The question belongs to Electrical Engineering (Linear System).
-Dominant- [34]
I’m crying looking at that.
5 0
3 years ago
The purification of hydrogen gas is possible by diffusion through a thin palladium sheet. Calculate the number of kilograms of h
diamong [38]

Answer:

M=0.0411 kg/h or 4.1*10^{-2} kg/h

Explanation:

We have to combine the following formula to find the mass yield:

M=JAt

M=-DAt(ΔC/Δx)

The diffusion coefficient : D=6.0*10^{-8} m/s^{2}

The area : A=0.25 m^{2}

Time : t=3600 s/h

ΔC: (0.64-3.0)kg/m^{3}

Δx: 3.1*10^{-3}m

Now substitute the  values

M=-DAt(ΔC/Δx)

M=-(6.0*10^{-8} m/s^{2})(0.25 m^{2})(3600 s/h)[(0.64-3.0kg/m^{3})(3.1*10^{-3}m)]

M=0.0411 kg/h or 4.1*10^{-2} kg/h

8 0
3 years ago
Other questions:
  • 12. The small space above the piston in which fuel is burned is called the
    10·1 answer
  • An electrochemical cell is composed of pure nickel and pure iron electrodes immersed in solutions of their divalent ions. If the
    13·1 answer
  • Lately, you have noticed some repetitive stress in your wrist. Which sign is most likely the cause of that stress and pain?
    7·1 answer
  • Explain how a CO2 cartridge powers the dragster you will be building. A good website to use is How Stuff Works. (howstuffworks.c
    7·2 answers
  • It has been estimated that 139.2x10^6 m^2 of rainforest is destroyed each day. assume that the initial area of tropical rainfore
    12·1 answer
  • According to OSHA standards, the air in the building that John works in is unsafe. The type of regulation that OSHA engages in i
    8·2 answers
  • The housing for a certain machinery product is made of two components, both aluminum castings. The larger component has the shap
    10·1 answer
  • Witch one is cuter compared to ur opinion calico kitten or grey?​
    5·1 answer
  • I really need help with my last topic,Hazard communication,if anyone can help me as soon as possible,that could be my Christmas
    12·1 answer
  • Good night. I need to go to bed. Byeeeeeeeeeeeee.​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!