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
Setler [38]
2 years ago
12

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, as defined in Section 5.4. Define these functions 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. Ask users to enter the list of numbers, and then choose which function to apply to those numbers. After the single number is returned from the correct function, display to the user the list of numbers, the function selected and the answer in a format that is easy to understand.
Computers and Technology
1 answer:
Vanyuwa [196]2 years ago
8 0

Answer:

from functools import reduce

def mean(mylist):

   score = reduce(lambda x,y: x + y, mylist)/ len(mylist)

   return score

def median(mylist):

   sorted(mylist)

   list_len = len(mylist) % 2

   i = round(len(mylist)/2)

   x = len(mylist)//2

   if list_len == 0:

       median = (mylist[x] + mylist[x+1]) / 2  

   else:

       median = mylist[i]

   return median

def mode(mylist):

   unique = set(mylist)

   unique = list(unique)

   collector = [mylist.count(key) for key in unique]

   maxi = max(collector)

   loc = collector.index(maxi)

   return unique[loc]

def main():

   scores = input( 'Enter list of numbers: ').split(",")

   scores = [int(score) for score in scores]

   

   operation = input('Enter operation: ')

   operator = ['mean', 'median', 'mode']

   

   for x in iter(list, 0):

       if operation in operator:

           break

       print("Invalid operation: ")

       operation = input('Enter operation')

   

   index_loc = operator.index(operation)

   

   if index_loc == 0:

       return mean(scores)

   elif index_loc == 1:

       return median(scores)

       #return np.median(scores)  can be used of the defined function

   elif index_loc == 2:

       #return stats.mode(scores)[0]  can be used of the defined function

       return mode(scores)

print( main( ) )

Explanation:

The main python function calls conditionally three statistical functions namely mean, median and mode. It prompts for user input for a list of integer numbers and a function name name to return the corresponding result.

You might be interested in
Think of an example in your life where a number could be described as data, information, and knowledge
zhannawk [14.2K]

Answer:

how many event you have been too in the last month (well non during this time but as an example)

Explanation:

4 0
2 years ago
What is the differnce between ''P4 and 4P''
34kurt
The number and letter are switched. This question needs more context to get a accurate answer.
5 0
2 years ago
Read 2 more answers
What kind of company would hire an Information Support and Service employee?
Anni [7]
A service company would hire an Information Support and Service employee.

hope it helps you!
6 0
3 years ago
Read 2 more answers
Calvin is creating a 3D shell of a turtle. He is creating a sculpted, intricate design for the pattern he wants on the shell, bu
PSYCHO15rus [73]
A is right I did this
7 0
1 year ago
Consider the following method.
JulsSmile [24]

Answer:

All

Explanation:

From the available options given in the question, once the while loop terminates any of the provided answers could be correct. This is because the arguments passed to the while loop indicate two different argument which both have to be true in order for the loop to continue. All of the provided options have either one or both of the arguments as false which would break the while loop. Even options a. and b. are included because both would indicate a false statement.

4 0
2 years ago
Other questions:
  • Why does the phrase "compatibility mode” appear when opening a workbook?
    6·2 answers
  • Panes created using the vertical split bar scroll together horizontally. true or false.
    12·1 answer
  • Evie clicks through her presentation slides and realizes they all have transition effects coming from the same location, from th
    13·1 answer
  • 1. Light of wavelength 900x10-9 m is emitted by a source. What is its frequency?​
    5·1 answer
  • What are the 5 characteristics of flowchart<br>​
    14·1 answer
  • What is the expression for the resultant value of three capacitance where C1 connected in parallel​
    11·1 answer
  • What does input allow a computer to do
    14·1 answer
  • Please answer this question​
    6·1 answer
  • Why does my internet keep disconnecting and reconnecting.
    9·1 answer
  • You want to store, organize, and manipulate your photos. what type of software do you need?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!