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
Arisa [49]
4 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]4 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]4 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
What should always be done before beginning any diagnosis?
vladimir2022 [97]

Answer:

c

Explanation:

if someone is wrong that they can help with

4 0
3 years ago
A seamless pipe carries 2400m³ of steam per hour at a pressure of 1.4N/mm².The velocity of flow is 30m/s.assuming the tensile st
MatroZZZ [7]

Answer:

yessss

Explanation:

7 0
3 years ago
Discuss the organizational system that you believe would be the most effective for the safety officer in a medium-sized (100-200
marin [14]

Answer:

A safety manager is a person who designs and maintains the safety elements at workplace. A balance should be required for production and the job in providing work environment. As a safety officer in a medium sized manufacturing facility the following organizational system can be designed and maintained:

  • Maintaining a workplace as per the guidelines by Occupational safety and health association. The rules and regulation should be such that maintains the manufacturing facilities.  
  • For warning to workers proper labelling, floor mapping, signs, posters should be used.  
  • Procurement and usage of safe tools.  
  • A guideline that describes safety standard and precautionary measures should be available to the workers. They should be aware about all the steps that needs to be taken in crisis.  
  • Ensuring that the workers have enough training safety and health or accident prevention.  
  • Identify and eliminate the hazardous elements from the workplace.  
  • A strict action should be taken against the worker in case of violation of rules and not adhering with guidelines.

3 0
3 years ago
Gold forms a substitutional solid solution with silver. Compute the number of gold atoms per cubic centimeter for a silver-gold
evablogger [386]

Answer:

Compute the number of gold atoms per cubic centimeter = 9.052 x 10^21 atoms/cm3

Explanation:

The step by step and appropriate substitution is as shown in the attachment.

From number of moles = Concentration x volume

number of moles = number of particles/ Avogadro's number

Volume = mass/density, the appropriate derivation to get the number of moles of atoms

5 0
3 years ago
How do you check battery state of charge with a voltmeter
cupoosta [38]

Answer:

Depends on the battery and the current type.

Is it AC or DC?

Explanation:

Could you mark as brainiest.

I need it for my account

Thank you! :)

8 0
3 years ago
Other questions:
  • Air is compressed adiabatically from p1 1 bar, T1 300 K to p2 15 bar, v2 0.1227 m3 /kg. The air is then cooled at constant volum
    13·1 answer
  • A heat pump receives heat from a lake that has an average wintertime temperature of 6o C and supplies heat into a house having a
    12·1 answer
  • The yield of a chemical process is being studied.The two most important variables are thought to be the pressure and the tempera
    9·1 answer
  • What is not required for current to flow through a conductor
    12·1 answer
  • An intranet is a restricted network that relies on Internet technologies to provide an Internet-like environment within the comp
    11·1 answer
  • In order to break even, your minimum selling price must be __________ your variable costs.
    10·1 answer
  • Is EPA is the organization that was formed to ensure safe and health working conditions for workers by setting and enforcing sta
    15·1 answer
  • What invention of the Middle Ages contributed to making books easily available?
    15·1 answer
  • A system samples a sinusoid of frequency 230 Hz at a rate of 175 Hz and writes the sampled signal to its output without further
    9·1 answer
  • A protocol is a set of rules or procedures, usually written, that should be followed in specific situations. Which of the follow
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!