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
Arisa [49]
2 years ago
5

A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set

of numbers. Define these functions, median and mode, in a module named stats.py. Also include a function named mean, which computes the average of a set of numbers. Each function should expect a list of numbers as an argument and return a single number. Each function should return 0 if the list is empty. Include a main function that tests the three statistical functions using the following list defined in main:List: [3, 1, 7, 1, 4, 10]
Engineering
2 answers:
emmasim [6.3K]2 years ago
7 0

Explanation:

def mean(lst):

   if not lst:

       return 0

   total = 0

   for num in lst:

       total + = num

   return total / len(lst)

 

def median(lst):

   if not lst:

       return 0

   samples = sorted(lst.copy())

   if len(samples) % 2 == 1:

       return samples[int(len(samples) / 2)]

   else:

       return (samples[int(len(samples) / 2)] + samples[int(len(samples) / 2) - 1]) / 2

 

def mode(lst):

   if not lst:

       return 0

   result = lst[0]

   count = 0

   for num in lst:

       if lst.count(num) >= count:

           count = lst.count(num)

           result = num

   return result

 

def main():

   userList = [3, 1, 7, 1, 4, 10]

   print('List:', userList)

   print('Mode:', mode(userList))

   print('Median:', median(userList))

   print('Mean:', mean(userList))

 

main()

iVinArrow [24]2 years ago
3 0

Answer:

Functions to create a median and mode of a set of numbers

Explanation:

def median(list):

   if len(list) == 0:

       return 0

   list.sort()

   midIndex = len(list) / 2

   if len(list) % 2 == 1:

       return list[midIndex]

   else:

       return (list[midIndex] + list[midIndex - 1]) / 2

def mean(list):

   if len(list) == 0:

       return 0

   list.sort()

   total = 0

   for number in list:

       total += number

   return total / len(list)

def mode(list):

   numberDictionary = {}

   for digit in list:

       number = numberDictionary.get(digit, None)

       if number == None:

           numberDictionary[digit] = 1

       else:

           numberDictionary[digit] = number + 1

   maxValue = max(numberDictionary.values())

   modeList = []

   for key in numberDictionary:

       if numberDictionary[key] == maxValue:

           modeList.append(key)

   return modeList

def main():

   print "Mean of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: ", mean(range(1, 11))

   print "Mode of [1, 1, 1, 1, 4, 4]:", mode([1, 1, 1, 1, 4, 4])

   print "Median of [1, 2, 3, 4]:", median([1, 2, 3, 4])

main()

You might be interested in
A center-point bending test was performed on a 2 in. x d in. wood lumber according to ASTM D198 procedure with a span of 4 ft an
Zigmanuir [339]

Answer:

3.03 INCHES

Explanation:

According to ASTM D198 ;

Modulus of rupture = ( M / I ) * y  ----- ( 1 )

M ( bending moment ) = R * length of span / 2

                                     = (120 * 10^3 ) * 48 / 2 = 288 * 10^4 Ib-in

I ( moment of inertia ) = bd^3 / 12

                                    = ( 2 )*( d )^3  / 12 =  2d^3 / 12

b = 2 in ,  d = ?

length of span = 4 * 12 = 48 inches

R = P  / 2 =  240 * 10^3 / 2 =   120 * 10^3 Ib

y ( centroid distance ) = d / 2  inches

back to equation ( 1 )

( M / I ) * y

940.3 ksi = ( 288 * 10^4 / 2d^3 / 12 ) * d / 2

                = ( 288 * 10^4 * 12 ) / 2d^3 )  * d / 2

940300  = 34560000* d / 4d^3

4d^3 ( 940300 ) = 34560000 d  ( divide both sides with d )

4d^2 = 34560000 / 940300

d^2 = 9.188   ∴ Value of d ≈ 3.03 in

8 0
2 years ago
At an impaired driver checkpoint, the time required to conduct the impairment test varies (according to an exponential distribut
professor190 [17]

Answer:

Option (d) 2 min/veh

Explanation:

Data provided in the question:

Average time required = 60 seconds

Therefore,

The maximum capacity that can be accommodated on the system, μ = 60 veh/hr

Average Arrival rate, λ = 30 vehicles per hour

Now,

The average time spent by the vehicle is given as

⇒ \frac{1}{\mu(1-\frac{\lambda}{\mu})}

thus,

on substituting the respective values, we get

Average time spent by the vehicle = \frac{1}{60(1-\frac{30}{60})}

or

Average time spent by the vehicle = \frac{1}{60(1-0.5)}

or

Average time spent by the vehicle = \frac{1}{60(0.5)}

or

Average time spent by the vehicle = \frac{1}{30} hr/veh

or

Average time spent by the vehicle = \frac{1}{30}\times60 min/veh

[ 1 hour = 60 minutes]

thus,

Average time spent by the vehicle = 2 min/veh

Hence,

Option (d) 2 min/veh

7 0
2 years ago
During normal operation, an electrical component experiences a constant rate of ohmic dissipation ini g = 0.01 W that causes the
Llana [10]

Answer:

Check the explanation

Explanation:

Kindly check the attached image below for the step by step explanation to your answer.

4 0
2 years ago
(a) If 15 kW of power from a heat reservoir at 500 K is input into a heat engine with an efficiency of 37%, what is the power ou
julsineya [31]

Answer:

(A) Power output will be 5.55 KW (b) lower temperature will be 315 K

Explanation:

We have given efficiency of heat engine \eta =37% = 0.37

Input power = 15 KW

Temperature of heat reservoir T_H=500K

(A) We know that \eta =\frac{output}{input}

So  [text]0.37=\frac{output}{15}[text]

Output = 5.55 KW

(B) We also know that [text]\eta =1-\frac{T_L}{T_H}0.37=\frac{output}{15}[text], here T_L  is lower temperature and T_H is higher temperature

So 0.37=1-\frac{T_L}{T_H}

0.37=1-\frac{T_L}{500}

T_L=315K

5 0
2 years ago
Explain why the fundamental software engineering principles of process, dependability, requirements management, and reuse are re
Svet_ta [14]

Answer:

1. Costs and frequency of change.

2. The most important ‘non-functional’ requirements. Different systems have different priorities for non-functional requirements.

3. The software lifetime and delivery schedule.

Explanation:

The process of requirement gathering is required in both generic and customized software.

• A document to define the development process is required in all type of software application.

• Updating is required in each type of software. For doing so, new version of each type of software is released.

• Maintenance is an important part of software development. It is required in each type of application development.

• Software has some minimum requirements to execute. So, platform dependability is considered in all software development.

5 0
2 years ago
Read 2 more answers
Other questions:
  • Small droplets of carbon tetrachloride at 68 °F are formed with a spray nozzle. If the average diameter of the droplets is 200 u
    10·1 answer
  • CHALLENGE ACTIVITY 2.8.1: Using constants in expressions. The cost to ship a package is a flat fee of 75 cents plus 25 cents per
    7·1 answer
  • A steam power plant operates on an ideal reheat- regenerative Rankine cycle and has a net power output of 80 MW. Steam enters th
    10·1 answer
  • An art collector is bidding on a statue that would complete a collection he is trying to assemble. The statue is being sold in a
    9·1 answer
  • Show that a chirped Gaussian pulse is compressed initially inside a single-mode fiber when ftC < 0. Derive expressions for th
    12·1 answer
  • Use the predicate specifications(x, y): x beats yF (x): x is an (American) football teamQ(x, y): x is quarterback of yL(x,y): x
    13·1 answer
  • The small washer is sliding down the cord OA. When it is at the midpoint, its speed is 28 m/s and its acceleration is 7 m/s 2 .
    13·1 answer
  • Madison and Oxford are the same distance from the equator and they are both near the ocean. Use the information on the map to an
    11·1 answer
  • Q10. Select the correct option for the following questions – (10 points, 2 each) a. After an edge dislocation has passed through
    15·1 answer
  • A glycerin pump is powered by a 5-kW electric motor. The pressure differential between the outlet and the inlet of the pump at f
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!