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]
3 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]3 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
2 of 10
ra1l [238]

Answer:

D

Explanation:

Just took the test

5 0
3 years ago
A simple CPM network has five activities, A, B, C, D, and E. A is an immediate predecessor of C and of D. B is also an immediate
Dmitrij [34]

Answer:

True

Explanation:

There are four paths in this network. A is an immediate predecessor of C and of D. B is also an immediate predecessor of C and of D. C and D are both immediate predecessors of E. Given the above scenario

4 0
3 years ago
A scientist conducted an experiment and discovered that certain plants grow faster when given a particular amount of fertilizer.
belka [17]

the answer is B: Replication, i put validity on e2020 and it was wrong.

3 0
4 years ago
Read 2 more answers
Does anyone know how to code
Bumek [7]

Answer:

yeah u just CODE

Explanation:

MARK BRAINLIEST PLEASE

THANK U!!!!!

3 0
3 years ago
Read 2 more answers
"the purpose of the ________ element is to contain the main content of a web page document."
Ket [755]
<span>the purpose of the 'CONTENT' element is to contain the main content of a web page document.</span>
7 0
3 years ago
Other questions:
  • How many people assume the product owner role in the Scrum framework?
    15·2 answers
  • Do questions have to be about school work on this website or can they be questions about video games?
    11·2 answers
  • Identify the function for the following computer part: CD-Drive Question 17 options: A. Storage B. Output C. Input D. Processing
    12·1 answer
  • To recover a deleted document, what would you choose in the info window?
    9·1 answer
  • What is an administrator?
    8·1 answer
  • Which of the following represents the biggest difference between asymmetric and symmetric cryptography?
    9·1 answer
  • Why there isn't in italian this app?​
    15·1 answer
  • What would be used by a business to assess how the business is working within its organization goals? O A. Information systems B
    8·1 answer
  • Me Completan Pliiiis
    11·1 answer
  • What is command is used to improve the vocabulary and in which tab is it found​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!