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
Press the ENTER key to do what?
Blababa [14]
Change the line in word, it basically returns
7 0
3 years ago
Which of these options highlights the need for learning algorithms
LiRa [457]

Answer: D.

Explanation:

7 0
3 years ago
Read 2 more answers
Write a program to draw a text-based graph of a mathematical function f(x)
Makovka662 [10]
I have a very good example of the program you need written on Python. You can use this (sorry for bad tabulation):
import math import math def main(): function = input("Enter a function f(x):\n") x = 0 y = 0 for rows in range(10,-11,-1): for col in range(-10,11,1): x=col roundfx = round(eval(function)) if roundfx == rows: print("o", end="") if rows==0 and col==0 and not rows == roundfx: print("+", end="") if col == 0 and not rows == 0 and not rows == roundfx: print("|", end="") if rows==0 and not col==0 and not rows == roundfx: print("-", end="") else: if not rows == 0: if not col == 0: if not rows == roundfx: print(" ", end="") print() main()
4 0
3 years ago
All it services and servers are equally critical. <br> a. True <br> b. False
g100num [7]

False

Not all IT services are equally critical. In an increasingly digital world whereby cyber threats are a big threat, it is vital to prioritize the critical assets in order to achieve digital resilience. This involves building tighter defenses in systems that are critical.

4 0
3 years ago
Saving a file as a new filename can be accomplished through the Save As dialog box? True<br> False
aliina [53]
Your answer would be true, (brainliest answer please)
7 0
3 years ago
Other questions:
  • The process of making raw materials into a finished product is known as
    14·2 answers
  • list the network characteristics of the wireless network(s) in the decode -- SSIDs, channels used, AP names, presence of Bluetoo
    6·1 answer
  • What are paragraphs separated by
    9·1 answer
  • Write the method makeNames that creates and returns a String array of new names based on the method’s two parameter arrays, arra
    9·1 answer
  • A software engineer is designing a new program. She decides to first define all the classes needed, and how they will interact w
    5·2 answers
  • Two system administrators who work in two different buildings for the same company want to open a communication channel between
    8·1 answer
  • What do workspaces allow a company to do?
    9·1 answer
  • These data provides the responses of 10 students in class A and in class B who were asked how many hours they slept lastThese da
    6·1 answer
  • Which statement describes what the Conditional Formatting option in Excel 2016 allows users to do?
    15·2 answers
  • How many 60 KB jpeg files can be stored on a 2 MB folder in your hard drive?​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!